tweak service worker

This commit is contained in:
Pig Fang 2020-06-01 16:20:28 +08:00
parent 1f842a09dd
commit ecc3d02167
2 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,9 @@
import { registerRoute } from 'workbox-routing'
import { CacheFirst, StaleWhileRevalidate } from 'workbox-strategies'
import {
CacheFirst,
StaleWhileRevalidate,
NetworkOnly,
} from 'workbox-strategies'
import { ExpirationPlugin } from 'workbox-expiration'
registerRoute(
@ -33,6 +37,18 @@ registerRoute(
}),
)
registerRoute(/.+\/\d+\.js$/, new NetworkOnly())
registerRoute(
/\/app\/\w{2,3}\.\w{7}\.js$/,
new CacheFirst({
cacheName: 'javascript-v1',
fetchOptions: {
credentials: 'omit',
},
}),
)
registerRoute(
({ request }) => request.destination === 'script',
new StaleWhileRevalidate({

View File

@ -12,7 +12,7 @@
{% endif %}
<script>
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js?v3')
navigator.serviceWorker.register('/sw.js?v4')
})
</script>
{% for link in links %}