Skip to content

Instantly share code, notes, and snippets.

@PhilJ
Last active March 31, 2016 10:49
Show Gist options
  • Save PhilJ/45a75e7a4742aed2b45e0c8fa0047d51 to your computer and use it in GitHub Desktop.
Save PhilJ/45a75e7a4742aed2b45e0c8fa0047d51 to your computer and use it in GitHub Desktop.
Use the new cache API to make the browser cache assets for offline functionality and register service worker to return cached assets.
// register service worker
navigator.serviceWorker.register('service-worker-cache-images.js', { scope: './' })
.then(navigator.serviceWorker.ready)
.then(function () {
console.log('service worker registered')
})
.catch(function (error) {
console.log('error when registering service worker', error, arguments)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment