|
| 1 | +--- |
| 2 | +layout: null |
| 3 | +--- |
| 4 | + |
| 5 | +var CACHE_NAME = 'pv8-web-cache-v1'; |
| 6 | + |
| 7 | +var urlsToCache = [ |
| 8 | + '/', |
| 9 | + '/css/main.css', |
| 10 | + {% for page in site.html_pages %} |
| 11 | + '{{ page.url }}', |
| 12 | + {% endfor %} |
| 13 | + {% for post in site.posts %} |
| 14 | + '{{ post.url }}', |
| 15 | + {% endfor %} |
| 16 | + {% for file in site.static_files %} |
| 17 | + {% if file.extname == '.js' or file.path contains '/media' %} '{{ file.path }}', {% endif %} |
| 18 | + {% endfor %} |
| 19 | +]; |
| 20 | + |
| 21 | +// {% if file.extname == '.js' or file.path contains '/portfolio/screenshots' or file.path contains '/portfolio/thumbnails' %} '{{ file.path }}', {% endif %} |
| 22 | + |
| 23 | +const CACHE_STATIC = [ |
| 24 | + '/css/main.css', |
| 25 | + '/media/gamification_balance.png', |
| 26 | + '/media/gamification_experience.png', |
| 27 | + '/media/gamification_gameelements.png', |
| 28 | + '/media/gamification_icon.png', |
| 29 | + '/media/gamification_journey.png', |
| 30 | + '/media/gamification_players.png', |
| 31 | + '/media/Python-logo-notext.png' |
| 32 | + ]; |
| 33 | + |
| 34 | + const CACHE_APP = [ |
| 35 | + '/', |
| 36 | + '/index.html', |
| 37 | + '/posts/', |
| 38 | + '/contact/' |
| 39 | + ]; |
| 40 | + |
| 41 | +self.addEventListener('install',function(event){ |
| 42 | + event.waitUntil( |
| 43 | + caches.open(CACHE_NAME) |
| 44 | + .then(function(cache) { |
| 45 | + console.log('Opened cache'); |
| 46 | + return cache.addAll(urlsToCache); |
| 47 | + }) |
| 48 | + ); |
| 49 | +}); |
| 50 | + |
| 51 | +self.addEventListener('fetch', function(event) { |
| 52 | + event.respondWith( |
| 53 | + caches.match(event.request) |
| 54 | + .then(function(response) { |
| 55 | + // Cache hit - return response |
| 56 | + if (response) { |
| 57 | + return response; |
| 58 | + } |
| 59 | + return fetch(event.request); |
| 60 | + } |
| 61 | + ) |
| 62 | + ); |
| 63 | +}); |
| 64 | + |
| 65 | +self.addEventListener('activate', function(event) { |
| 66 | + |
| 67 | + var cacheWhitelist = [CACHE_NAME]; |
| 68 | + |
| 69 | + event.waitUntil( |
| 70 | + caches.keys().then(function(cacheNames) { |
| 71 | + return Promise.all( |
| 72 | + cacheNames.map(function(cacheName) { |
| 73 | + if (cacheWhitelist.indexOf(cacheName) === -1) { |
| 74 | + return caches.delete(cacheName); |
| 75 | + } |
| 76 | + }) |
| 77 | + ); |
| 78 | + }) |
| 79 | + ); |
| 80 | +}); |
0 commit comments