|
@@ -16,25 +16,25 @@ console.log("sw printing after chrome58StopHere ", stop);
|
|
|
if (!stop) {
|
|
|
self.addEventListener("fetch", event => {
|
|
|
// Prevent the default, and handle the request ourselves.
|
|
|
- event.respondWith(
|
|
|
- (async function() {
|
|
|
- // console.log("fetch intercepted");
|
|
|
- // Try to get the response from a cache.
|
|
|
- const cachedResponse = await caches.match(event.request);
|
|
|
- // Return it if we found one.
|
|
|
- if (cachedResponse) {
|
|
|
- console.log("cache res", event.request.url);
|
|
|
- return cachedResponse;
|
|
|
- }
|
|
|
+ if (
|
|
|
+ event.request.url.startsWith(
|
|
|
+ "https://ecs-test-static.qmth.com.cn/comm-ques-bank/dev/audio"
|
|
|
+ ) ||
|
|
|
+ event.request.url.startsWith(
|
|
|
+ "https://ecs-static.qmth.com.cn/comm-ques-bank/prod/audio/"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ event.respondWith(
|
|
|
+ (async function() {
|
|
|
+ // console.log("fetch intercepted");
|
|
|
+ // Try to get the response from a cache.
|
|
|
+ const cachedResponse = await caches.match(event.request);
|
|
|
+ // Return it if we found one.
|
|
|
+ if (cachedResponse) {
|
|
|
+ console.log("cache res", event.request.url);
|
|
|
+ return cachedResponse;
|
|
|
+ }
|
|
|
|
|
|
- if (
|
|
|
- event.request.url.startsWith(
|
|
|
- "https://ecs-test-static.qmth.com.cn/comm-ques-bank/dev/audio"
|
|
|
- ) ||
|
|
|
- event.request.url.startsWith(
|
|
|
- "https://ecs-static.qmth.com.cn/comm-ques-bank/prod/audio/"
|
|
|
- )
|
|
|
- ) {
|
|
|
console.log("fetch audio intercept, try to load all");
|
|
|
const res = await fetch(event.request.url);
|
|
|
|
|
@@ -46,18 +46,6 @@ if (!stop) {
|
|
|
if (contentLength === 0) {
|
|
|
return fetch(event.request);
|
|
|
}
|
|
|
- // console.log("content-length", contentLength);
|
|
|
- // self.sessionStorage.setItem("test-sw", "1");
|
|
|
- // self.postMessage({
|
|
|
- // url: event.request.url,
|
|
|
- // progress: 1,
|
|
|
- // });
|
|
|
-
|
|
|
- // self.addEventListener('message', function(event){
|
|
|
- // console.log("SW Received Message: " + event.data);
|
|
|
- // console.log(event);
|
|
|
- // event.ports[0].postMessage("SW Says 'Hello back!'");
|
|
|
- // });
|
|
|
|
|
|
// Step 3: read the data
|
|
|
let receivedLength = 0; // received that many bytes at the moment
|
|
@@ -111,11 +99,11 @@ if (!stop) {
|
|
|
});
|
|
|
|
|
|
return responseFinal.clone();
|
|
|
- }
|
|
|
- // If we didn't find a match in the cache, use the network.
|
|
|
- return fetch(event.request);
|
|
|
- })()
|
|
|
- );
|
|
|
+ // If we didn't find a match in the cache, use the network.
|
|
|
+ // return fetch(event.request);
|
|
|
+ })()
|
|
|
+ );
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
console.log("sw printing end");
|