Back to Serwist

NetworkOnly

docs-serwist-runtime-caching-caching-strategies-network-only.md

latest1.2 KB
Original Source

NetworkOnly

First added

Workbox

About

An implementation of the network only request strategy.

This class is useful if you require specific requests to only be fulfilled from the network.

If the network request fails, this will throw a SerwistError exception.

Parameters

  • pluginsPlugins to use in conjunction with this caching strategy.
  • fetchOptions — Options passed to non-navigation fetch() calls made by this strategy.
  • networkTimeoutSeconds — If set, any network requests that fail to respond within the timeout will fallback to the cache.

Usage

sw.ts

import { NetworkOnly, Serwist } from "serwist";

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

More resources

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