Skip to main content

CacheableResponsePlugin

First added

Workbox

About

A class implementing the cacheWillUpdate lifecycle callback. This makes it easier to add in cacheability checks to requests made via Serwist’s built-in strategies.

Options

See CacheableResponse’s options.

Usage

import { CacheableResponsePlugin, StaleWhileRevalidate } from "serwist";

serwist.registerCapture(
  ({ url }) => url.pathname.startsWith("/api/"),
  new StaleWhileRevalidate({
    plugins: [
      new CacheableResponsePlugin({
        statuses: [0, 200],
        headers: {
          "X-Is-Cacheable": "true",
        },
      }),
    ],
  }),
);