Created
October 11, 2017 09:40
-
-
Save aofleejay/6f49a7655b6cb77b5193f01db606163e to your computer and use it in GitHub Desktop.
Cache assets in install event
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
const VERSION = '1' | |
const CACHE_KEY = `cache-v${VERSION}` | |
const assetsToCache = [ | |
'/', | |
'/assets/css/app.css', | |
'/assets/js/app.js', | |
'/assets/images/icons/icon-16x16.png', | |
'/assets/images/icons/icon-24x24.png', | |
'/assets/images/icons/icon-36x36.png', | |
'/assets/images/icons/icon-64x64.png', | |
'/assets/images/icons/icon-128x128.png', | |
'/assets/images/icons/icon-256x256.png', | |
'/assets/images/icons/icon-512x512.png', | |
'/assets/images/background1.jpg', | |
'/assets/images/background2.jpg', | |
'/assets/images/background3.jpg', | |
] | |
self.addEventListener('install', event => { | |
event.waitUntil( | |
caches.open(CACHE_KEY) | |
.then(cache => cache.addAll(assetsToCache)) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment