forked from rebeccapeltz/sw-fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
27 lines (24 loc) · 755 Bytes
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// const loc = new URL(location);
const params = (new URL(location)).searchParams;
const isOn = params.get('enable') === '1';
console.log('isOn', isOn)
const blur = params.get('blur') || 0;
const q = params.get('q') || 'auto';
const f = params.get('f') || 'auto';
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./sw.js');
});
}
self.addEventListener('fetch', (e) => {
console.log('fetch event triggered')
// if (isOn) {
if (e.request.url.indexOf('.jpg') >= 0) {
const url = `https://res.cloudinary.com/picturecloud7/image/fetch/f_${f}/q_${q}/e_blur:${blur}/${e.request.url}`
console.log(url)
e.respondWith(
fetch(url)
)
}
// }
});