some updates to page loading performance and general performance.

added a ServiceWorker which caches stuff
This commit is contained in:
2025-10-12 17:36:11 +02:00
parent a7847f6bff
commit ccabb5395c
9 changed files with 483 additions and 100 deletions

300
js/post/prism.js Normal file

File diff suppressed because one or more lines are too long

32
js/post/sw.js Normal file
View File

@@ -0,0 +1,32 @@
const CACHE_NAME = 'offline-v1';
const ASSETS = [
'/css/main.css',
'/js/shared/theme.js',
'/js/post/download.js',
'/js/post/lazyimg.js',
'/package/js/prism.min.js',
'/package/js/prism-python.min.js',
'/package/js/mathjax.js',
'/css/icons/back.webp',
'/css/icons/written.webp',
'/css/icons/date.webp',
'/css/icons/magnifier.webp',
'/css/icons/save.webp',
'/css/icons/script.webp'
];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS)));
});
self.addEventListener('fetch', e => {
e.respondWith(
caches.match(e.request).then(res => res || fetch(e.request).then(resp => {
if (e.request.url.startsWith(self.location.origin)) {
const copy = resp.clone();
caches.open(CACHE_NAME).then(c => c.put(e.request, copy));
}
return resp;
}))
);
});