workbox-expiration#ExpirationPlugin JavaScript Examples

The following examples show how to use workbox-expiration#ExpirationPlugin. 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 vote down vote up
// 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 vote down vote up
// 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 vote down vote up
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 vote down vote up
/*
 * 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 vote down vote up
// 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 vote down vote up
// 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 vote down vote up
// 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 pack11ty with MIT License 6 votes vote down vote up
// Google Analytics
registerRoute(
  ({ request }) =>
    request.url === 'https://www.google-analytics.com/analytics.js',
  new CacheFirst({
    cacheName: 'shell',
    plugins: [
      new ExpirationPlugin({
        maxAgeSeconds: 10 * 24 * 60 * 60, // 10 Days
      }),
    ],
  })
);
Example #9
Source File: custom-sw.js    From tclone with MIT License 6 votes vote down vote up
// requests to cors-anywhere proxy, cache-first
registerRoute(
  ({ url }) => url.origin === "https://cors-anywhere.herokuapp.com",
  new CacheFirst({
    cacheName: "previews",
    plugins: [
      new ExpirationPlugin({
        maxEntries: 50,
        maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
      }),
    ],
  })
);
Example #10
Source File: custom-sw.js    From tclone with MIT License 6 votes vote down vote up
// images cache first
registerRoute(
  ({ request, url }) =>
    request.destination === "image" &&
    (url.origin === process.env.REACT_APP_API_SERVER ||
      url.origin === process.env.PUBLIC_URL),
  new CacheFirst({
    cacheName: "images",
    plugins: [
      new ExpirationPlugin({
        maxEntries: 20,
        maxAgeSeconds: 2 * 24 * 60 * 60, // 2 Days
      }),
    ],
  })
);
Example #11
Source File: service-worker.js    From rahat-vendor with GNU Affero General Public License v3.0 6 votes vote down vote up
// 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 #12
Source File: service-worker.js    From covid with GNU General Public License v3.0 6 votes vote down vote up
// 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 ReactCookbook-source with MIT License 6 votes vote down vote up
// 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 covid with GNU General Public License v3.0 6 votes vote down vote up
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 #15
Source File: service-worker.js    From ReactCookbook-source with MIT License 6 votes vote down vote up
registerRoute(
    ({url}) => url.origin === 'https://fonts.gstatic.com',
    new CacheFirst({
        cacheName: 'fonts',
        plugins: [
            new CacheableResponsePlugin({
                statuses: [0, 200],
            }),
            new ExpirationPlugin({
                maxAgeSeconds: 60 * 60 * 7,
                maxEntries: 5
            }),
        ],
    })
);
Example #16
Source File: service-worker.js    From ReactCookbook-source with MIT License 6 votes vote down vote up
// 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 #17
Source File: service-worker.js    From SauceKudasai with MIT License 6 votes vote down vote up
// 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 CacheFirst({
		cacheName: 'images',
		plugins: [
			// Ensure that once this runtime cache reaches a maximum size the
			// least-recently used images are removed.
			new ExpirationPlugin({ maxEntries: 10 }),
		],
	})
);
Example #18
Source File: service-worker.js    From WhatSend with MIT License 6 votes vote down vote up
// 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 #19
Source File: service-worker.js    From zero-neko with MIT License 6 votes vote down vote up
// 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 #20
Source File: sw-template.js    From Pf2eTools with MIT License 6 votes vote down vote up
/*
the base case route - for images that have fallen through every other route
this is external images, for homebrew as an example
*/
registerRoute(({request}) => request.destination === "image", new NetworkFirst({
	cacheName: "external-image-cache",
	plugins: [
		// this is a safeguard against an utterly massive cache - these numbers may need tweaking
		new ExpirationPlugin({maxAgeSeconds: 7 /* days */ * 24 * 60 * 60, maxEntries: 100, purgeOnQuotaError: true}),
	],
}));
Example #21
Source File: service-worker.js    From Queen with MIT License 6 votes vote down vote up
// 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 #22
Source File: service-worker.js    From covid with GNU General Public License v3.0 6 votes vote down vote up
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 #23
Source File: service-worker.js    From covid with GNU General Public License v3.0 6 votes vote down vote up
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 #24
Source File: service-worker.js    From covid with GNU General Public License v3.0 6 votes vote down vote up
registerRoute(
  ({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.csv'),
  new StaleWhileRevalidate({
    cacheName: 'csv',
    plugins: [
      new ExpirationPlugin({ maxEntries: 50 }),
    ],
  })
);
Example #25
Source File: service-worker.js    From covid with GNU General Public License v3.0 6 votes vote down vote up
registerRoute(
  ({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.pbf'),
  new StaleWhileRevalidate({
    cacheName: 'pbf',
    plugins: [
      new ExpirationPlugin({ maxEntries: 50 }),
    ],
  })
);