Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions desktop-app/resources/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -7864,4 +7864,4 @@ document.addEventListener("DOMContentLoaded", function () {
});
});
}
});
});
4 changes: 2 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -7864,4 +7864,4 @@ document.addEventListener("DOMContentLoaded", function () {
});
});
}
});
});
30 changes: 28 additions & 2 deletions sw.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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 => {
Expand Down
Loading