style(pwa): use 2 spaces indentation for sw.js
and swcache.js
This commit is contained in:
parent
52084f85d4
commit
1a041e0443
2 changed files with 84 additions and 86 deletions
|
@ -1,6 +1,5 @@
|
|||
---
|
||||
layout: compress
|
||||
|
||||
# The list to be cached by PWA
|
||||
---
|
||||
|
||||
|
|
|
@ -28,19 +28,19 @@ function isExcluded(url) {
|
|||
return false;
|
||||
}
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(cacheName).then(cache => {
|
||||
caches.open(cacheName).then((cache) => {
|
||||
return cache.addAll(resource);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then(keyList => {
|
||||
caches.keys().then((keyList) => {
|
||||
return Promise.all(
|
||||
keyList.map(key => {
|
||||
keyList.map((key) => {
|
||||
if (key !== cacheName) {
|
||||
return caches.delete(key);
|
||||
}
|
||||
|
@ -56,28 +56,28 @@ self.addEventListener('message', (event) => {
|
|||
}
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(response => {
|
||||
caches.match(event.request).then((response) => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return fetch(event.request).then(response => {
|
||||
return fetch(event.request).then((response) => {
|
||||
const url = event.request.url;
|
||||
|
||||
if (event.request.method !== 'GET' ||
|
||||
if (
|
||||
event.request.method !== 'GET' ||
|
||||
!verifyDomain(url) ||
|
||||
isExcluded(url)) {
|
||||
isExcluded(url)
|
||||
) {
|
||||
return response;
|
||||
}
|
||||
|
||||
/*
|
||||
see: <https://developers.google.com/web/fundamentals/primers/service-workers#cache_and_return_requests>
|
||||
*/
|
||||
/* see: <https://developers.google.com/web/fundamentals/primers/service-workers#cache_and_return_requests> */
|
||||
let responseToCache = response.clone();
|
||||
|
||||
caches.open(cacheName).then(cache => {
|
||||
caches.open(cacheName).then((cache) => {
|
||||
/* console.log('[sw] Caching new resource: ' + event.request.url); */
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
|
@ -87,4 +87,3 @@ self.addEventListener('fetch', event => {
|
|||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue