Added service workers

This commit is contained in:
Jori Lallo
2016-07-21 22:06:43 -07:00
parent e5b175a86e
commit d2780233c1
2 changed files with 28 additions and 23 deletions

View File

@@ -27,14 +27,14 @@
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
// if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('/service-worker.js') navigator.serviceWorker.register('/service-worker.js')
// .then(function(reg) { .then(function(reg) {
// console.log('SW registration succeeded'); console.log('SW registration succeeded');
// }).catch(function(error) { }).catch(function(error) {
// console.log('SW registration failed: ' + error); console.log('SW registration failed: ' + error);
// }); });
// }; };
</script> </script>
</body> </body>
</html> </html>

View File

@@ -59,21 +59,26 @@ Cache.prototype.addAll||(Cache.prototype.addAll=function(t){function e(t){this.n
// in the URL should be fine for this sample. // in the URL should be fine for this sample.
// - toolbox.cacheFirst let us to use the predefined cache strategy for those // - toolbox.cacheFirst let us to use the predefined cache strategy for those
// requests. // requests.
global.toolbox.router.get(/\.ytimg\.com\//, global.toolbox.cacheFirst, { // global.toolbox.router.get(/\.ytimg\.com\//, global.toolbox.cacheFirst, {
// Use a dedicated cache for the responses, separate from the default cache. // // Use a dedicated cache for the responses, separate from the default cache.
cache: { // cache: {
name: 'youtube-thumbnails', // name: 'youtube-thumbnails',
// Store up to 10 entries in that cache. // // Store up to 10 entries in that cache.
maxEntries: 10, // maxEntries: 10,
// Expire any entries that are older than 30 seconds. // // Expire any entries that are older than 30 seconds.
maxAgeSeconds: 30 // maxAgeSeconds: 30
} // }
}); // });
// By default, all requests that don't match our custom handler will use the // Index page and assets
// toolbox.networkFirst cache strategy, and their responses will be stored in global.toolbox.router.get(/^\/$/, global.toolbox.cacheFirst);
// the default cache. global.toolbox.router.get(/^\/dashboard/, global.toolbox.cacheFirst);
global.toolbox.router.default = global.toolbox.networkFirst; global.toolbox.router.get(/\/static\//, global.toolbox.cacheFirst);
// API get calls
global.toolbox.router.get(/\/api\//, global.toolbox.networkFirst);
// global.toolbox.router.default = global.toolbox.networkFirst;
// Boilerplate to ensure our service worker takes control of the page as soon // Boilerplate to ensure our service worker takes control of the page as soon
// as possible. // as possible.