Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Created December 12, 2018 14:48
Show Gist options
  • Select an option

  • Save Antoinebr/0ca172e6b75e1afacbb1b53ae677c56a to your computer and use it in GitHub Desktop.

Select an option

Save Antoinebr/0ca172e6b75e1afacbb1b53ae677c56a to your computer and use it in GitHub Desktop.
workbox-strategies.js
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.0.1/workbox-sw.js");
workbox.skipWaiting();
workbox.clientsClaim();
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
self.__precacheManifest = [
{
"url": "/wp-content/themes/monbraceletnato/css/app.css",
"revision": "bfc709359d2bsdddff9Z322LLPPPll9932dd4b021"
},
{
"url": "/wp-content/themes/monbraceletnato/js/app.bundle.js",
"revision": "026022bqq87ad2c78c34a4982119PPlm036ooo1ae"
},
{
"url": "/wp-content/themes/monbraceletnato/img/logo.png",
"revision": "1c56bab3cb87ad2c78c34a4d36a422"
},
{
"url": "/wp-content/themes/monbraceletnato/img/header-logo-small-black.png",
"revision": "1c533ab3cb87ad2s78c0d34a4d3sds422"
},
{
"url": "/wp-content/themes/monbraceletnato/js/libs/jquery.js",
"revision": "1c533ab3cb87lm2s7ds0d34a4d3sds422"
},
{
"url": "/offline/",
"revision": "e3481cd53bdkllmsqsppp72ss88067d"
}
].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerRoute(/(https:\/\/fonts.googleapis.com)/, workbox.strategies.staleWhileRevalidate(), 'GET');
/*
| --------------------------------------------------------------------------
| Caching the home page
| --------------------------------------------------------------------------
*/
workbox.routing.registerRoute( '/', (args) => {
return workbox.strategies.networkFirst()
.handle(args).then((response) => (!response) ? caches.match('/offline/') : response);
});
/*
| --------------------------------------------------------------------------
| Caching of the product pages
| --------------------------------------------------------------------------
*/
const productsNetworkFirstHandler = workbox.strategies.networkFirst({
cacheName: 'products',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 30,
maxAgeSeconds: 2 * 30 * 24 * 60 * 60,
}),
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
]
});
workbox.routing.registerRoute(/\/produit\//, (args) => {
return productsNetworkFirstHandler.handle(args).then((response) => (!response) ? caches.match('/offline/') : response);
});
/*
| --------------------------------------------------------------------------
| Caching the categories
| --------------------------------------------------------------------------
*/
const catsNetworkFirstHandler = workbox.strategies.networkFirst({
cacheName: 'products-cats',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 10,
maxAgeSeconds: 2 * 30 * 24 * 60 * 60,
}),
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
]
});
workbox.routing.registerRoute(/\/categorie-produit\//, (args) => {
return catsNetworkFirstHandler.handle(args).then((response) => (!response) ? caches.match('/offline/') : response);
});
/*
| --------------------------------------------------------------------------
| Caching the blog pages
| --------------------------------------------------------------------------
*/
const blogNetworkFirstHandler = workbox.strategies.networkFirst({
cacheName: 'blog',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 10,
maxAgeSeconds: 2 * 30 * 24 * 60 * 60,
}),
new workbox.cacheableResponse.Plugin({
statuses: [200]
}),
]
});
workbox.routing.registerRoute(/\/blog\//, (args) => {
return blogNetworkFirstHandler.handle(args).then((response) => (!response) ? caches.match('/offline/') : response);
});
/*
| --------------------------------------------------------------------------
| Caching instagram feed
| --------------------------------------------------------------------------
| https://monbraceletnato.fr/wp-json/antoine/instagram
*/
workbox.routing.registerRoute('https://monbraceletnato.fr/wp-json/antoine/instagram', workbox.strategies.cacheFirst(), 'GET');
/*
| --------------------------------------------------------------------------
| Caching FontAwesome
| --------------------------------------------------------------------------
*/
workbox.routing.registerRoute(/(https:\/\/maxcdn.bootstrapcdn.com)/, workbox.strategies.cacheFirst(), 'GET');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment