diff --git a/desktop-app/resources/js/script.js b/desktop-app/resources/js/script.js index e908605..42e56f4 100644 --- a/desktop-app/resources/js/script.js +++ b/desktop-app/resources/js/script.js @@ -2788,7 +2788,7 @@ document.addEventListener("DOMContentLoaded", function () { const currentValue = markdownEditor.value; if (currentValue === lastPushedValue) return; - const inputType = e ? e.inputType : ''; + const inputType = e && typeof e.inputType === 'string' ? e.inputType : ''; if (!pendingState) { pendingState = { @@ -7864,4 +7864,4 @@ document.addEventListener("DOMContentLoaded", function () { }); }); } -}); \ No newline at end of file +}); diff --git a/script.js b/script.js index e908605..42e56f4 100644 --- a/script.js +++ b/script.js @@ -2788,7 +2788,7 @@ document.addEventListener("DOMContentLoaded", function () { const currentValue = markdownEditor.value; if (currentValue === lastPushedValue) return; - const inputType = e ? e.inputType : ''; + const inputType = e && typeof e.inputType === 'string' ? e.inputType : ''; if (!pendingState) { pendingState = { @@ -7864,4 +7864,4 @@ document.addEventListener("DOMContentLoaded", function () { }); }); } -}); \ No newline at end of file +}); diff --git a/sw.js b/sw.js index 39816d9..88ec578 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const CACHE_NAME = 'markdown-viewer-cache-v3.7.2'; +const CACHE_NAME = 'markdown-viewer-cache-v3.7.3'; // PERF-011: Split precache into critical (local files) and lazy (CDN libraries) // Critical assets are precached during SW install for instant offline startup @@ -19,6 +19,14 @@ const CDN_ORIGINS = [ 'cdn.jsdelivr.net' ]; +const NETWORK_FIRST_LOCAL_PATHS = new Set([ + '/', + '/index.html', + '/script.js', + '/styles.css', + '/sw.js' +]); + self.addEventListener('install', event => { event.waitUntil( caches.open(CACHE_NAME) @@ -45,7 +53,25 @@ self.addEventListener('fetch', event => { const isCDN = CDN_ORIGINS.some(origin => url.hostname.includes(origin)); if (isLocal) { - // Stale-While-Revalidate strategy for local code assets + const localPath = url.pathname.endsWith('/') ? '/' : url.pathname; + const shouldUseNetworkFirst = + event.request.mode === 'navigate' || NETWORK_FIRST_LOCAL_PATHS.has(localPath); + + if (shouldUseNetworkFirst) { + event.respondWith( + caches.open(CACHE_NAME).then(cache => { + return fetch(event.request).then(networkResponse => { + if (networkResponse && networkResponse.status === 200) { + cache.put(event.request, networkResponse.clone()); + } + return networkResponse; + }).catch(() => cache.match(event.request)); + }) + ); + return; + } + + // Stale-While-Revalidate strategy for non-code local assets event.respondWith( caches.open(CACHE_NAME).then(cache => { return cache.match(event.request).then(cachedResponse => {