bypass off origin requests
This commit is contained in:
parent
be2919c1cb
commit
e68d92cfc1
1 changed files with 12 additions and 3 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
const version = self.gapp.version;
|
const version = self.gapp.version;
|
||||||
|
const origin = self.location.origin;
|
||||||
const stats = {
|
const stats = {
|
||||||
hit: 0,
|
hit: 0,
|
||||||
miss: 0,
|
miss: 0,
|
||||||
fetch: 0,
|
fetch: 0,
|
||||||
cache: 0,
|
cache: 0,
|
||||||
|
bypass: 0,
|
||||||
preload: 0,
|
preload: 0,
|
||||||
timer: undefined
|
timer: undefined
|
||||||
};
|
};
|
||||||
|
|
@ -19,7 +21,7 @@ function update() {
|
||||||
|
|
||||||
function report() {
|
function report() {
|
||||||
console.log('sw cache', stats);
|
console.log('sw cache', stats);
|
||||||
stats.hit = stats.miss = stats.fetch = stats.cache = stats.preload = 0;
|
stats.hit = stats.miss = stats.fetch = stats.cache = stats.bypass = stats.preload = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('sw entry point');
|
debug('sw entry point');
|
||||||
|
|
@ -131,10 +133,17 @@ self.addEventListener('install', (event) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
|
const { request,preloadResponse } = event;
|
||||||
|
if (request.url.indexOf(origin) !== 0) {
|
||||||
|
// console.log('off origin request', request.url);
|
||||||
|
stats.bypass++;
|
||||||
|
return event.respondWith(fetch(request));
|
||||||
|
}
|
||||||
|
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
cacheFirst({
|
cacheFirst({
|
||||||
request: event.request,
|
request: request,
|
||||||
preloadResponsePromise: event.preloadResponse,
|
preloadResponsePromise: preloadResponse,
|
||||||
fallbackUrl: '//static.grid.space/img/logo_gs.png',
|
fallbackUrl: '//static.grid.space/img/logo_gs.png',
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue