Advertisement
Guest User

workbox-caching-examples

a guest
Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Caches all requests ending in .html
  3.  * Handle those requests using a network-first strategy.
  4.  */
  5. workboxSW.router.registerRoute(
  6.     /\.html$/,
  7.     workboxSW.strategies.networkFirst( [] )
  8. );
  9.  
  10. /* The setup cache has a maximum size of 20 images,
  11. * and once that's reached, the least-recently used entry will be deleted.
  12. * Additionally, any entries older than 1 week will be deleted. */
  13. workboxSW.router.registerRoute(
  14.     '/images/(.*)',
  15.     workboxSW.strategies.cacheFirst({
  16.         cacheName: 'images',
  17.         cacheExpiration: {
  18.             maxEntries: 20,
  19.             maxAgeSeconds: 7 * 24 * 60 * 60,
  20.         },
  21.         cacheableResponse: {statuses: [0, 200]},
  22.     })
  23. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement