IamBramer / iambramer

Development files for iambramer.com
https://iambramer.com/
0 stars 0 forks source link

Update Service Worker #25

Open IamBramer opened 6 years ago

IamBramer commented 6 years ago

Setup a service worker that has proper cache invalidation. The below github project has a service worker that can be built with gulp and will hash files.

https://github.com/GoogleChromeLabs/sw-precache

IamBramer commented 6 years ago

Use a Cache then network approach like shown in the Offline Cookbook. This will show the cache first and then update the page when the network data arrives.

IamBramer commented 6 years ago
{
  runtimeCaching: [{
    urlPattern: /\/projects\//,
    handler: 'networkFirst',
    options: {
        cache: {
          maxEntries: 10,
          name: 'projects-cache'
        }
    }
  }, {
    urlPattern: /\/words\//,
    handler: 'networkFirst',
    options: {
        cache: {
          maxEntries: 10,
          name: 'words-cache'
        }
    }
  }],
  // ...other options as needed...
}
IamBramer commented 6 years ago

Remember to register service worker.

https://github.com/GoogleChromeLabs/sw-precache/blob/master/demo/app/js/service-worker-registration.js