Skip to content

Commit a35bb93

Browse files
committed
fix: service worker no-cache-homepage + API version 0.3.6
Root cause of stale homepage: SW cached / at install time + cacheFirst for all non-API requests → always served old version. Fix: - No PRECACHE (no caching at install) - HTML pages (no ext): networkFirst - Static assets (JS,CSS,img): cacheFirst - Dynamic cache name (timestamp) → auto-invalidation - skipWaiting + clients.claim for immediate activation Also: - API version: 0.3.4 → 0.3.6 (in demo serverless)
1 parent f12e3ef commit a35bb93

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

demo/app/routes/api/ping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ app.get('/', (c) => {
1010
return c.json({
1111
ok: true,
1212
framework: 'KISS',
13-
version: '0.3.4',
13+
version: '0.3.6',
1414
jamstack: true,
1515
serverless: true,
1616
timestamp: new Date().toISOString(),

packages/kiss-core/src/cli/build-ssg.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,19 @@ async function buildSSG(options: BuildSSGOptions = {}): Promise<void> {
335335
writeFileSync(join(outputDir, 'manifest.json'), JSON.stringify(manifest, null, 2));
336336
console.log('[KISS SSG] PWA manifest.json generated');
337337

338-
// Simple CacheFirst service worker
339-
const swCode = `const CACHE = 'kiss-v1';
340-
const PRECACHE = ['/', '/index.html'];
338+
// Smart service worker: networkFirst for HTML+API, cacheFirst for assets
339+
// No precaching — the old PRECACHE pattern caused stale index.html.
340+
const swCode = `const CACHE = 'kiss-${Date.now()}';
341341
self.addEventListener('install', (e) => {
342-
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(PRECACHE)));
343342
self.skipWaiting();
344343
});
345344
self.addEventListener('activate', (e) => {
346345
e.waitUntil(clients.claim());
347346
});
348347
self.addEventListener('fetch', (e) => {
349-
if (e.request.url.includes('/api/')) {
348+
const url = new URL(e.request.url);
349+
// HTML pages and API calls: always go to network first
350+
if (!url.pathname.match(/\\.[a-z0-9]+$/i) || url.pathname.includes('/api/')) {
350351
e.respondWith(networkFirst(e.request));
351352
} else {
352353
e.respondWith(cacheFirst(e.request));

0 commit comments

Comments
 (0)