perf: 100% Lighthouse score — contrast, CLS, caching fixes
- Font preload eliminates layout shift (CLS 0) - Dual accent colors: --accent for filled buttons, --accent-text for text on dark bg - All WCAG AA contrast ratios met (buttons, links, badges, countdown) - Language picker: position absolute instead of fixed - CoinGecko rates proxied with 2min server-side cache (no CORS, no rate limit) - English as default inline text (no empty→text shift)
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
header('Cache-Control: public, max-age=60');
|
||||
|
||||
// Server-side cache: fetch from CoinGecko at most once per 2 minutes
|
||||
$cacheFile = __DIR__ . '/../data/rates_cache.json';
|
||||
$cacheTTL = 120; // seconds
|
||||
|
||||
if (file_exists($cacheFile)) {
|
||||
$cached = json_decode(file_get_contents($cacheFile), true);
|
||||
if ($cached && (time() - ($cached['_time'] ?? 0)) < $cacheTTL) {
|
||||
unset($cached['_time']);
|
||||
header('Cache-Control: public, max-age=60');
|
||||
echo json_encode($cached);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$url = 'https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur,usd,chf';
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
@@ -15,8 +27,27 @@ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response !== false && $httpCode === 200) {
|
||||
echo $response;
|
||||
} else {
|
||||
http_response_code(502);
|
||||
echo json_encode(['error' => 'Failed to fetch rates']);
|
||||
$data = json_decode($response, true);
|
||||
if ($data) {
|
||||
$data['_time'] = time();
|
||||
file_put_contents($cacheFile, json_encode($data));
|
||||
unset($data['_time']);
|
||||
header('Cache-Control: public, max-age=60');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// On error, serve stale cache if available
|
||||
if (file_exists($cacheFile)) {
|
||||
$cached = json_decode(file_get_contents($cacheFile), true);
|
||||
if ($cached) {
|
||||
unset($cached['_time']);
|
||||
header('Cache-Control: public, max-age=30');
|
||||
echo json_encode($cached);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
http_response_code(502);
|
||||
echo json_encode(['error' => 'Failed to fetch rates']);
|
||||
|
||||
Reference in New Issue
Block a user