Ремонт: cache-busting для CSS/JS (?v=хэш)
All checks were successful
Deploy Remont Site / deploy (push) Successful in 18s
All checks were successful
Deploy Remont Site / deploy (push) Successful in 18s
Ссылки на style.css/app.js получают ?v=<md5 содержимого>. При изменении стилей/скриптов URL меняется → браузер подтягивает свежую версию сразу, не дожидаясь истечения 7-дневного кэша (была видна старая CSS после правок). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KjyzuPoH9T5k3oCbKEEazy
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const HERE = __dirname;
|
||||
@@ -34,6 +35,14 @@ const OUT = process.env.OUT || path.join(HERE, 'out');
|
||||
const OUT_IMG = path.join(OUT, 'images');
|
||||
const cfg = JSON.parse(fs.readFileSync(path.join(HERE, 'site.config.json'), 'utf8'));
|
||||
|
||||
// хэш содержимого ассета → ?v=… чтобы браузер сбрасывал кэш при изменении CSS/JS
|
||||
function assetVer(rel) {
|
||||
const buf = fs.readFileSync(path.join(HERE, 'assets', rel));
|
||||
return crypto.createHash('md5').update(buf).digest('hex').slice(0, 8);
|
||||
}
|
||||
const CSS_VER = assetVer('style.css');
|
||||
const JS_VER = assetVer('app.js');
|
||||
|
||||
// ─── утилиты ──────────────────────────────────────────────
|
||||
const esc = (s) => String(s == null ? '' : s)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
@@ -420,7 +429,7 @@ function buildHtml(rooms, sections) {
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Onest:wght@400;500;600&display=swap&subset=cyrillic,cyrillic-ext,latin" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="stylesheet" href="css/style.css?v=${CSS_VER}">
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><rect width='100' height='100' rx='20' fill='%237C8A66'/><path d='M25 70V42l25-18 25 18v28H56V52H44v18z' fill='%23F7F3EA'/></svg>">
|
||||
</head>
|
||||
<body>
|
||||
@@ -476,7 +485,7 @@ ${sectionsHtml}
|
||||
<img id="lbImg" src="" alt="">
|
||||
</div>
|
||||
|
||||
<script src="js/app.js"></script>
|
||||
<script src="js/app.js?v=${JS_VER}"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user