Skip to content

Instantly share code, notes, and snippets.

@stefanledin
Created December 25, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanledin/a4e408db1fd8ff163fd0a545d57964f6 to your computer and use it in GitHub Desktop.
Save stefanledin/a4e408db1fd8ff163fd0a545d57964f6 to your computer and use it in GitHub Desktop.
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');
if (workbox) {
const cacheName = 'my-site-cache';
workbox.routing.registerRoute(
'/',
workbox.strategies.networkFirst({
cacheName
})
);
workbox.routing.registerRoute(
/wp-content\/uploads/,
workbox.strategies.cacheFirst({
cacheName
})
);
workbox.routing.registerRoute(
/wp-content\/themes\/theme-name\/assets/,
workbox.strategies.staleWhileRevalidate({
cacheName
})
);
workbox.routing.registerRoute(
/cache\/autoptimize/,
workbox.strategies.staleWhileRevalidate({
cacheName
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment