Skip to content

Instantly share code, notes, and snippets.

@ankitamasand
Last active October 31, 2018 19:53
Show Gist options
  • Save ankitamasand/5b7480a705cdd057a177fb449365a841 to your computer and use it in GitHub Desktop.
Save ankitamasand/5b7480a705cdd057a177fb449365a841 to your computer and use it in GitHub Desktop.
self.addEventListener('install', (event) => {
let CACHE_NAME = 'xyz-cache'
let urlsToCache = [
'/',
'/styles/main.css',
'/scripts/bundle.js'
]
event.waitUntil(
/* open method available on caches, takes in the name of cache as the first paramter. It returns a promise that resolves to the instance of cache
All the above URLS can be added to cache using the addAll method. */
caches.open(CACHE_NAME)
.then (cache => cache.addAll(urlsToCache))
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment