Fix persistent caching: no-store/no-cache headers, SW v4, versioned asset URLs
This commit is contained in:
1 parent
86914a7329
commit
ea20d31217
3 files changed
+15
-5
No files matched your search
@@ -16,7 +16,7 @@
|
|||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Playfair+Display:wght@500;600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Playfair+Display:wght@500;600&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css?v=4">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="app">
|
<div class="app">
|
||||||
@@ -301,7 +301,7 @@
|
|||||||
</div><!-- .app -->
|
</div><!-- .app -->
|
||||||
|
|
||||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||||
<script src="app.js"></script>
|
<script src="app.js?v=4"></script>
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
|
|||||||
+3
-3
@@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const CACHE = 'weather-v3';
|
const CACHE = 'weather-v4';
|
||||||
|
|
||||||
// App shell — cached on install for offline use
|
// App shell — cached on install for offline use
|
||||||
const PRECACHE = [
|
const PRECACHE = [
|
||||||
'/',
|
'/',
|
||||||
'/app.js',
|
'/app.js?v=4',
|
||||||
'/style.css',
|
'/style.css?v=4',
|
||||||
'/manifest.json',
|
'/manifest.json',
|
||||||
'/icons/icon.svg'
|
'/icons/icon.svg'
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -105,6 +105,16 @@ function ensurePushConfigured() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML: never cache (always revalidate so SW/app updates are picked up immediately)
|
||||||
|
app.use('/', (req, res, next) => {
|
||||||
|
if (req.path === '/' || req.path.endsWith('.html')) {
|
||||||
|
res.setHeader('Cache-Control', 'no-store');
|
||||||
|
} else if (req.path.endsWith('.css') || req.path.endsWith('.js') || req.path === '/sw.js' || req.path === '/manifest.json') {
|
||||||
|
// Short-lived cache — browser revalidates every 60 s but still gets a 304 fast
|
||||||
|
res.setHeader('Cache-Control', 'no-cache');
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.get('/healthz', (_req, res) => {
|
app.get('/healthz', (_req, res) => {
|
||||||
|
|||||||
Reference in new issue
Block a user