Files
mc-webui/app/static/js/sw.js
MarekWo 9a0d05ae93 fix(search): remove double hash in channel names, add FTS5 syntax help
Channel names from device already include # prefix — removed hardcoded #
from search results badge. Added (?) help button with search syntax
examples and link to FTS5 docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 07:38:37 +01:00

82 lines
2.9 KiB
JavaScript

const CACHE_NAME = 'mc-webui-v9';
const ASSETS_TO_CACHE = [
'/',
'/static/css/style.css',
'/static/js/app.js',
'/static/js/dm.js',
'/static/js/contacts.js',
'/static/js/message-utils.js',
'/static/js/filter-utils.js',
'/static/js/console.js',
'/static/images/android-chrome-192x192.png',
'/static/images/android-chrome-512x512.png',
// Bootstrap 5.3.2 (local)
'/static/vendor/bootstrap/css/bootstrap.min.css',
'/static/vendor/bootstrap/js/bootstrap.bundle.min.js',
// Bootstrap Icons 1.11.2 (local)
'/static/vendor/bootstrap-icons/bootstrap-icons.css',
'/static/vendor/bootstrap-icons/fonts/bootstrap-icons.woff2',
'/static/vendor/bootstrap-icons/fonts/bootstrap-icons.woff',
// Emoji Picker Element 1.28.1 (local)
'/static/vendor/emoji-picker-element/index.js',
'/static/vendor/emoji-picker-element/picker.js',
'/static/vendor/emoji-picker-element/database.js',
'/static/vendor/emoji-picker-element-data/en/emojibase/data.json',
// Socket.IO client 4.x (local)
'/static/vendor/socket.io/socket.io.min.js',
// Console page
'/console'
];
// Install event - cache core assets
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => cache.addAll(ASSETS_TO_CACHE))
.then(() => self.skipWaiting())
);
});
// Activate event - clean old caches
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames
.filter((name) => name !== CACHE_NAME)
.map((name) => caches.delete(name))
);
}).then(() => self.clients.claim())
);
});
// Fetch event - hybrid strategy:
// - Cache-first for vendor libraries (static, unchanging)
// - Network-first for app content (dynamic, needs updates)
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url);
// Cache-first for vendor libraries (Bootstrap, Icons)
if (url.pathname.includes('/static/vendor/')) {
event.respondWith(
caches.match(event.request)
.then((cachedResponse) => {
return cachedResponse || fetch(event.request)
.then((response) => {
// Cache the fetched vendor file for future use
return caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, response.clone());
return response;
});
});
})
);
} else {
// Network-first for everything else (app code, API calls, dynamic content)
event.respondWith(
fetch(event.request)
.catch(() => caches.match(event.request))
);
}
});