workbox-strategies#StaleWhileRevalidate JavaScript Examples
The following examples show how to use
workbox-strategies#StaleWhileRevalidate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: service-worker.js From ReactCookbook-source with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({url}) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({maxEntries: 50}),
],
})
);
Example #2
Source File: service-worker.js From ResoBin with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
// Customize this strategy as needed, e.g., by changing to CacheFirst.
registerRoute(
({ url }) =>
url.origin === self.location.origin && url.pathname.endsWith('.png'),
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
)
Example #3
Source File: service-worker.js From esc-configurator with GNU Affero General Public License v3.0 | 6 votes |
registerRoute(
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.json'),
new StaleWhileRevalidate({
cacheName: 'json',
plugins: [
/*
* Ensure that once this runtime cache reaches a maximum size the
* least-recently used images are removed.
*/
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #4
Source File: service-worker.js From esc-configurator with GNU Affero General Public License v3.0 | 6 votes |
/*
* An example runtime caching route for requests that aren't handled by the
* precache, in this case same-origin .png requests like those from in public/
*/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && (url.pathname.endsWith('.png') || url.pathname === '/favicon.ico'),
// Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
/*
* Ensure that once this runtime cache reaches a maximum size the
* least-recently used images are removed.
*/
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #5
Source File: service-worker.js From portfolio-react with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({url}) =>
url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({maxEntries: 50}),
],
})
)
Example #6
Source File: service-worker.js From generator-webapp-rocket with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #7
Source File: service-worker.js From pack11ty with MIT License | 6 votes |
// Images
registerRoute(
({ request }) => request.destination === 'image',
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxEntries: 200,
maxAgeSeconds: 90 * 24 * 60 * 60, // 90 Days
}),
],
})
);
Example #8
Source File: service-worker.js From rahat-vendor with GNU Affero General Public License v3.0 | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) =>
url.origin === self.location.origin &&
(url.pathname.endsWith('.png') ||
url.pathname.endsWith('.css') ||
url.pathname.endsWith('.ico') ||
url.pathname.endsWith('.js')), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'assets',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 })
]
})
);
Example #9
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) =>
url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 })
]
})
)
Example #10
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.geojson'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'geojson',
plugins: [
new ExpirationPlugin({ maxEntries: 15 }),
],
})
);
Example #11
Source File: service-worker.js From ReactCookbook-source with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({url}) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({maxEntries: 50}),
],
})
);
Example #12
Source File: service-worker.js From ReactCookbook-source with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #13
Source File: service-worker.js From WhatSend with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #14
Source File: service-worker.js From zero-neko with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #15
Source File: service-worker.js From Queen with MIT License | 6 votes |
// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #16
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
registerRoute(
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.pbf'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'pbf',
plugins: [
new ExpirationPlugin({ maxEntries: 0 }),
],
})
);
Example #17
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
registerRoute(
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.html'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'html',
plugins: [
new ExpirationPlugin({ maxEntries: 0 }),
],
})
);
Example #18
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
registerRoute(
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.csv'),
new StaleWhileRevalidate({
cacheName: 'csv',
plugins: [
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #19
Source File: service-worker.js From covid with GNU General Public License v3.0 | 6 votes |
registerRoute(
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.pbf'),
new StaleWhileRevalidate({
cacheName: 'pbf',
plugins: [
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);
Example #20
Source File: service-worker.js From ReactCookbook-source with MIT License | 5 votes |
registerRoute(
({url}) => url.origin === 'https://fonts.googleapis.com',
new StaleWhileRevalidate({
cacheName: 'stylesheets',
})
);
Example #21
Source File: sw.js From iris-messenger with MIT License | 5 votes |
registerRoute(
() => true,
new StaleWhileRevalidate()
);
Example #22
Source File: custom-sw.js From tclone with MIT License | 5 votes |
// fallback scripts
registerRoute(
({ request }) => request.destination === "script",
new StaleWhileRevalidate({
cacheName: "scripts",
})
);
Example #23
Source File: service-worker.js From pack11ty with MIT License | 5 votes |
// default strategy
setDefaultHandler(
new StaleWhileRevalidate({
cacheName: 'default',
plugins: [new BroadcastUpdatePlugin()],
})
);