Slide 35
Slide 35 text
sw-toolbox-config.js Content
iFixit API Route
toolbox.fastest
fallback logic
Image Route
toolbox.cacheFirst
LRU cache expiration
toolbox.router.get('/api/2.0/(.*)', toolbox.fastest, {
origin: /^https:\/\/www.ifixit.com$/
});
const MISSING_IMAGE = '/images/missing.png';
toolbox.cache(MISSING_IMAGE);
function imageHandler(request, values, options) {
return toolbox.cacheFirst(request, values, options).catch(() => {
return caches.match(MISSING_IMAGE);
});
}
toolbox.router.get('/(.*)', imageHandler, {
cache: {name: 'image-cache', maxEntries: 50},
origin: /cloudfront.net$/
});