Netlify TTL Cache Plugin

1.0.2 · active · verified Sun Apr 19

netlify-plugin-ttl-cache is a Netlify build plugin designed to address common runtime errors, such as 'ChunkLoadError,' in single-page applications (SPAs) that utilize code splitting (e.g., `React.lazy`). Netlify's default behavior is to replace all static assets upon each new deployment, which can lead to issues if a user's browser attempts to load an old, cached JavaScript chunk that no longer exists on the server. This plugin, currently at version 1.0.2, mitigates this by allowing users to specify a build output directory and a Time-To-Live (TTL) for assets within it, effectively persisting legacy immutable assets across deployments for a defined period. This ensures that previously served assets remain available, preventing broken user experiences without manual intervention. The plugin is configured declaratively via `netlify.toml` and does not require changes to application JavaScript code.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart installs the plugin and configures it in `netlify.toml` to cache assets in the 'build' directory for 90 days, preventing chunk-load errors.

npm i -D netlify-plugin-ttl-cache

# netlify.toml
[[plugins]]
package = "netlify-plugin-ttl-cache"
  [plugins.inputs]
  path = "build" # Your build output directory, e.g., 'dist', 'out'
  ttl = 90 # Assets will be cached for 90 days
  # exclude = "^/_nuxt/" # Optional: Regular expression string pattern for files to exclude

view raw JSON →