some updates to page loading performance and general performance.
added a ServiceWorker which caches stuff
This commit is contained in:
300
js/post/prism.js
Normal file
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
32
js/post/sw.js
Normal 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;
|
||||
}))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user