Cache the data for react-server pages for blazing fast client transitions.
First, install the module:
npm install --save react-server-data-bundle-cacheThen, install the cache:
import DataBundleCache from "react-server-data-bundle-cache" DataBundleCache.install();Then, opt into bundle caching in pages:
class MyPage { handleRoute() { DataBundleCache.optIn(); ... } ... }Then, link to your page with the bundleData option:
<Link bundleData={true} path="/mypage">My page</Link>If you really want to be slick, preload the bundle:
DataBundleCache.preload('/mypage');ttl: How long (in milliseconds) a bundle is good for.max: How many bundles may be kept in the cache.
Pass options as an object to the install method:
DataBundleCache.install({ ttl: 10*60*1000, // Ten minutes. max: 10, // Ten bundles. });That's it! Enjoy! 🚀