1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { registerRoute } from 'workbox-routing/registerRoute.js';
- import { StaleWhileRevalidate } from 'workbox-strategies/StaleWhileRevalidate.js';
- import { CacheFirst } from 'workbox-strategies/CacheFirst.js';
- import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin.js';
- import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin.js';
- import './_version.js';
- function googleFontsCache(options = {}) {
- const sheetCacheName = `${options.cachePrefix || 'google-fonts'}-stylesheets`;
- const fontCacheName = `${options.cachePrefix || 'google-fonts'}-webfonts`;
- const maxAgeSeconds = options.maxAgeSeconds || 60 * 60 * 24 * 365;
- const maxEntries = options.maxEntries || 30;
-
- registerRoute(({ url }) => url.origin === 'https://fonts.googleapis.com', new StaleWhileRevalidate({
- cacheName: sheetCacheName,
- }));
-
- registerRoute(({ url }) => url.origin === 'https://fonts.gstatic.com', new CacheFirst({
- cacheName: fontCacheName,
- plugins: [
- new CacheableResponsePlugin({
- statuses: [0, 200],
- }),
- new ExpirationPlugin({
- maxAgeSeconds,
- maxEntries,
- }),
- ],
- }));
- }
- export { googleFontsCache };
|