Back to Serwist

cacheOnNavigation

docs-next-configuring-cache-on-navigation.md

latest685 B
Original Source

cacheOnNavigation

First added

[email protected]

Default

false

About

Enables additional route caching when users navigate through pages with next/link. This improves the user experience in some cases but it also adds a bit of overhead due to additional network calls.

How it works

It overrides history.pushState and history.replaceState. When these functions are called, they call a function that posts a message containing the URL in their parameters to the @serwist/next worker, telling it to add this URL to the cache.

Usage

next.config.mjs

withSerwistInit({
  swSrc: "app/sw.ts",
  swDest: "public/sw.js",
  cacheOnNavigation: true,
});