CacheFirst
First added
Workbox
About
An implementation of the cache first request strategy.
A cache first strategy is useful for assets that have been revisioned, such as URLs like “/styles/example.a8f5f1.css”, since they can be cached for long periods of time.
If the network request fails, and there is no cache match, this will throw a SerwistError
exception.
Parameters
cacheName
— Cache name to store and retrieve requests. Defaults to Serwist’s default cache names.plugins
— Plugins to use in conjunction with this caching strategy.fetchOptions
— Options passed to non-navigationfetch()
calls made by this strategy.matchOptions
— The CacheQueryOptions passed to anycache.match()
orcache.put()
call made by this strategy.
Usage
import { CacheFirst, Serwist } from "serwist";
const serwist = new Serwist({
runtimeCaching: [
{
matcher: ({ request }) => request.destination === "style",
handler: new CacheFirst(),
},
],
});
More resources
Here is a list of resources you can read to learn more about CacheFirst
: