From 646580e6dcf460c889a3e20e3166f3f3c38bdb9c Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 24 May 2026 11:53:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=80=E5=8F=91=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=EF=BC=9Arouter.php=20=E6=B3=A8=E5=85=A5=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 JS/CSS/图片/字体等静态资源添加 ETag、Last-Modified、Cache-Control 响应头, 支持 304 Not Modified,避免浏览器每次完整重新下载。其余文件走原有逻辑。 --- public/router.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/public/router.php b/public/router.php index 7606629..f0fdcae 100644 --- a/public/router.php +++ b/public/router.php @@ -1,7 +1,76 @@ = filemtime($file)) + ) { + http_response_code(304); + exit; + } + + header('ETag: ' . $etag); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'); + header('Cache-Control: public, max-age=86400'); + header('X-Content-Type-Options: nosniff'); + + $mimeMap = [ + 'js' => 'application/javascript', + 'css' => 'text/css', + 'png' => 'image/png', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'gif' => 'image/gif', + 'svg' => 'image/svg+xml', + 'ico' => 'image/x-icon', + 'webp' => 'image/webp', + 'woff' => 'font/woff', + 'woff2' => 'font/woff2', + 'ttf' => 'font/ttf', + 'eot' => 'application/vnd.ms-fontobject', + 'otf' => 'font/otf', + 'map' => 'application/json', + 'json' => 'application/json', + 'xml' => 'application/xml', + 'pdf' => 'application/pdf', + 'zip' => 'application/zip', + 'mp3' => 'audio/mpeg', + 'mp4' => 'video/mp4', + 'wav' => 'audio/wav', + 'avi' => 'video/x-msvideo', + ]; + header('Content-Type: ' . ($mimeMap[$ext] ?? 'application/octet-stream')); + readfile($file); + exit; + } + + // PHP、HTML 等文件交给 PHP 内置服务器处理 return false; } else { require __DIR__ . "/index.php";