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.
npm install netlify-plugin-ttl-cacheVerified import paths — ran on the pinned version, not inferred.
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.
Ensure the `path` input in `netlify.toml` accurately reflects your site's build output directory (e.g., `path = "dist"` for a `dist` folder).
Choose a `ttl` value (in days) that balances cache efficiency with user experience, typically ranging from 30 to 180 days for most applications with immutable assets. Monitor your site for any lingering chunk-load errors post-deployment.
Verify that your build tool (e.g., Webpack, Vite, Create React App) is configured to generate unique, content-hashed filenames for assets that are meant to be cached by this plugin.
Install `netlify-plugin-ttl-cache` and configure it in your `netlify.toml` with the correct `path` to your build output and an appropriate `ttl` value (e.g., `path = "build"`, `ttl = 90`).
Ensure the `path` input is present and correctly defined as a string, for example, `path = "build"`.
Ensure the `ttl` input is present and correctly defined as a number (integer), for example, `ttl = 90` (without quotes).
No dependency data recorded yet.