This file contains hidden or 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
| self.addEventListener('activate', function(event) { | |
| event.waitUntil( | |
| caches | |
| .keys() | |
| .then(function(cacheNames) { | |
| return Promise.all( | |
| cacheNames | |
| .filter(function(cacheName) { | |
| // Return true if you want to remove this cache, | |
| // but remember that caches are shared across |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| // Try the cache | |
| caches | |
| .match(event.request) | |
| .then(function(response) { | |
| if (response) { | |
| return response | |
| } | |
| return fetch(event.request) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| // Try the cache | |
| caches | |
| .match(event.request) | |
| .then(function(response) { | |
| // Fall back to network | |
| return response || fetch(event.request) | |
| }) | |
| .catch(function() { |
This file contains hidden or 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
| // Here is the code in the sw.js: | |
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| caches | |
| .open('mysite-dynamic') | |
| .then(function(cache) { | |
| return fetch(event.request) | |
| .then(function(response) { | |
| cache.put(event.request, response.clone()) |
This file contains hidden or 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
| // Here is the code in the app.js: | |
| var networkDataReceived = false | |
| startSpinner() | |
| // fetch fresh data | |
| var networkUpdate = fetch('/data.json') | |
| .then(function(response) { | |
| return response.json() | |
| }) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| fetch(event.request).catch(function() { | |
| return caches.match(event.request) | |
| }) | |
| ) | |
| }) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| caches.match(event.request).then(function(response) { | |
| return response || fetch(event.request) | |
| }) | |
| ) | |
| }) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith(fetch(event.request)) | |
| }) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith(caches.match(event.request)) | |
| }) |
This file contains hidden or 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
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| self | |
| .caches | |
| .open('mysite-dynamic') | |
| .then(function(cache) { | |
| return cache | |
| .match(event.request) | |
| .then(function (response) { | |
| if (response != null) { |