Skip to main content

CacheOnly

First added

Workbox

About

An implementation of the cache only request strategy.

This class is useful if you already have your own precaching step.

If 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.
  • pluginsPlugins to use in conjunction with this caching strategy.
  • fetchOptions — Options passed to non-navigation fetch() calls made by this strategy.
  • matchOptions — The CacheQueryOptions passed to any cache.match() or cache.put() call made by this strategy.

Usage

import { CacheOnly, Serwist } from "serwist";

const serwist = new Serwist({
  runtimeCaching: [
    {
      matcher: ({ url }) => url.pathname.startsWith("/app/v2/"),
      handler: new CacheOnly(),
    },
  ],
});

More resources

Here is a list of resources you can read to learn more about CacheOnly: