Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created August 28, 2019 06:14
Show Gist options
  • Save tkssharma/858909fd48f4642ece3cd5c4adc138dc to your computer and use it in GitHub Desktop.
Save tkssharma/858909fd48f4642ece3cd5c4adc138dc to your computer and use it in GitHub Desktop.
workbox.routing.registerRoute(
new RegExp('.css$'),
workbox.strategies.cacheFirst({
cacheName: 'poc-cache-Stylesheets',
plugins: [
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 7, // cache for one week
maxEntries: 20, // only cache 20 request
purgeOnQuotaError: true,
}),
],
}),
);
workbox.routing.registerRoute(
new RegExp('.(png|svg|jpg|jpeg)$'),
workbox.strategies.cacheFirst({
cacheName: 'poc-cache-Images',
plugins: [
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 7,
maxEntries: 50,
purgeOnQuotaError: true,
}),
],
}),
);
workbox.routing.registerRoute(
new RegExp('https://randomuser.me/api/'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'poc-cache-employees',
cacheExpiration: {
maxAgeSeconds: 60 * 30, //cache the news content for 30mn
},
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment