-
-
Save Schepp/adbc1579e8d1a38087e087a40b205322 to your computer and use it in GitHub Desktop.
This serviceworker doesn't work for Samsung Internet Browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); | |
workbox.setConfig({ debug: false }); | |
workbox.routing.registerRoute(/\/assets\/.*\.(?:js|css|woff|woff2|png|svg|json)(\?v=.*|)$/, workbox.strategies.cacheFirst({ | |
cacheName: 'assets', | |
plugins: [ | |
new workbox.cacheableResponse.Plugin({ | |
statuses: [0, 200], | |
}), | |
new workbox.expiration.Plugin({ | |
maxEntries: 100, | |
}), | |
new workbox.expiration.Plugin({ | |
maxAgeSeconds: 604800, | |
}), | |
], | |
}), 'GET'); | |
workbox.routing.registerRoute(/\.(?:png|svg)$/, workbox.strategies.networkFirst({ | |
cacheName: 'images', | |
plugins: [ | |
new workbox.cacheableResponse.Plugin({ | |
statuses: [0, 200], | |
}), | |
new workbox.expiration.Plugin({ | |
maxEntries: 100, | |
}), | |
new workbox.expiration.Plugin({ | |
maxAgeSeconds: 604800, | |
}), | |
], | |
}), 'GET'); | |
const documentCacheOptions = { | |
cacheName: 'documents', | |
plugins: [ | |
new workbox.cacheableResponse.Plugin({ | |
statuses: [0, 200], | |
}), | |
new workbox.expiration.Plugin({ | |
maxEntries: 100, | |
}), | |
new workbox.expiration.Plugin({ | |
maxAgeSeconds: 3600, | |
}), | |
], | |
}; | |
workbox.routing.registerRoute(/^$/, workbox.strategies.networkFirst(documentCacheOptions), 'GET'); | |
workbox.routing.registerRoute(/^.*\/$/, workbox.strategies.networkFirst(documentCacheOptions), 'GET'); | |
workbox.routing.registerRoute(/\.(?:html)$/, workbox.strategies.networkFirst(documentCacheOptions), 'GET'); | |
workbox.routing.registerRoute(/_(?:aid|bid|vid)$/, workbox.strategies.networkFirst(documentCacheOptions), 'GET'); | |
const thirdPartyCacheOptions = { | |
plugins: [ | |
new workbox.cacheableResponse.Plugin({ | |
statuses: [0, 200], | |
}), | |
], | |
}; | |
workbox.routing.registerRoute(/^https:\/\/script.ioam.de\/iam.js/, workbox.strategies.staleWhileRevalidate(thirdPartyCacheOptions), 'GET'); | |
workbox.routing.registerRoute(/^https:\/\/www.googletagservices.com\/tag\/js\/gpt.js/, workbox.strategies.staleWhileRevalidate(thirdPartyCacheOptions), 'GET'); | |
workbox.routing.registerRoute(/^https:\/\/www.youtube.com\/iframe_api/, workbox.strategies.staleWhileRevalidate(thirdPartyCacheOptions), 'GET'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment