Сайт: версия style.css по содержимому — починить кеш на телефоне
This commit is contained in:
parent
aa50d83bf0
commit
a5dd4d46de
27 changed files with 47 additions and 27 deletions
|
|
@ -9,6 +9,26 @@
|
|||
* строкой в NAV.
|
||||
*/
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||
|
||||
// Версия оформления по содержимому. Адрес CSS менялся в 005, но nginx отдаёт
|
||||
// /assets/style.css с кешем на неделю — телефон приносил старую версию по тому
|
||||
// же адресу, и галерея ехала (нет .grid / aspect-ratio). Хеш в query решает
|
||||
// это честно: изменился файл — изменился адрес.
|
||||
let cssVersion = null;
|
||||
function styleVersion() {
|
||||
if (cssVersion === null) {
|
||||
const css = fs.readFileSync(path.join(ROOT, "assets", "style.css"));
|
||||
cssVersion = createHash("sha1").update(css).digest("hex").slice(0, 10);
|
||||
}
|
||||
return cssVersion;
|
||||
}
|
||||
|
||||
export function esc(s) {
|
||||
return String(s)
|
||||
.replace(/&/g, "&")
|
||||
|
|
@ -40,7 +60,7 @@ export function page({ title, description = "", body, active = "", mainClass = "
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>${esc(title)}</title>
|
||||
${description ? `<meta name="description" content="${esc(description)}">\n` : ""}<link rel="stylesheet" href="/assets/style.css">
|
||||
${description ? `<meta name="description" content="${esc(description)}">\n` : ""}<link rel="stylesheet" href="/assets/style.css?v=${styleVersion()}">
|
||||
${headExtra ? `${headExtra}\n` : ""}</head>
|
||||
<body>
|
||||
<header class="top">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue