Add Service Worker

less than 1 minute read

https://github.com/GoogleChrome/sw-precache#install

$ npm install --save-dev sw-precache
sw-precache --config=path/to/sw-precache-config.js --verbose

https://codelabs.developers.google.com/codelabs/sw-precache/#5

Add the following <script> tag to the bottom of your index.html file to register your service worker:

<script>
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js').then(function() { 
    console.log("Service Worker Registered"); 
  });
}
</script>

How does SW-Precache works

ref: https://medium.com/@Huxpro/how-does-sw-precache-works-2d99c3d3c725

Categories:

Updated: