Skip to content

Instantly share code, notes, and snippets.

@vietlq
Forked from voduytuan/sw.js
Created September 10, 2016 15:01
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 vietlq/89f5e74b6b057872589dc1dbddd68b39 to your computer and use it in GitHub Desktop.
Save vietlq/89f5e74b6b057872589dc1dbddd68b39 to your computer and use it in GitHub Desktop.
importScripts('js/sw-toolbox.js');
toolbox.options.debug = false;
toolbox.precache(['/']);
//FOr homepage, we use fastest so that it update new content for next request
toolbox.router.get('/', toolbox.fastest);
// The route for the images
toolbox.router.get('/js/(.*)', toolbox.cacheFirst, {cache: {name: 'js', maxEntries: 5, maxAgeSeconds: 8640000}});
toolbox.router.get('/css/(.*)', toolbox.cacheFirst, {cache: {name: 'css', maxEntries: 5, maxAgeSeconds: 8640000}});
toolbox.router.get('/imgs/(.*)', toolbox.cacheFirst, {cache: {name: 'imgs'}});
//for api domain
var apiorigin = /api\.teamcrop\.com/;
// var apiorigin = /api\.teamcrop\.com/;
toolbox.router.get(/.*fulldata.*/, toolbox.cacheFirst, {cache: {name: 'fulldata', maxEntries: 20, maxAgeSeconds: 8640000}, origin: apiorigin});
toolbox.router.get(/.*photoavatar.*/, toolbox.cacheFirst, {cache: {name: 'photoavatar', maxEntries: 20, maxAgeSeconds: 8640000}, origin: apiorigin});
var ajaxList = [
/v1\/companies\/init\?/,
/v1\/\w+\?.*$/,
/v1\/\w+\/\d+\?.*$/,
/v1\/\w+\/ids\?.*$/
]
for (var i = 0; i < ajaxList.length; i++) {
toolbox.router.get(ajaxList[i], toolbox.networkFirst, {cache: {name: 'ajax'}, origin: apiorigin});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment