1
mirror of https://github.com/jakejarvis/netlify-plugin-cache.git synced 2025-04-26 08:45:23 -04:00
2020-06-06 10:15:46 -04:00

3.0 KiB

netlify-plugin-cache

npm

A generic cache plugin for saving and restoring files and/or folders between Netlify builds for impressive speed improvements. Worry less about running out of build minutes!

In other words, this plugin is a pretty wrapper around Netlify's native cache utility — it isn't tied to any specific static site generator (on purpose).

Install

Add the following to your netlify.toml configuration:

[[plugins]]
package = "netlify-plugin-cache"
  [plugins.inputs]
  paths = ["resources", "_vendor", "folder/file.md"]

This plugin only takes one input (which is required) named paths, an array of paths to files and/or folders relative to your project's root. These files/folders are restored before a build and saved in cache after a build if it is successful.

Read more about plugin configuration at the official Netlify Plugin docs.

Usage examples

  • Hugo: Caching the resources directory can speed up your build greatly if you process a lot of images via Hugo pipes. You can also cache the public directory to avoid completely rebuilding the entire site on each deploy. More info here.
  • Gatsby: By default, the .cache directory holds persistent data between builds. You can also cache the dist directory to avoid completely rebuilding the entire site on each deploy. More info here.
  • Next.js: The .next directory holds the build output. More info here.
  • Anything else: This is the reason I kept this plugin as generic as possible! Research the caching behavior of your static site generator (and how to customize it if necessary). Feel free to make a PR and add it here as another example, too!

Debugging

This plugin doesn't provide a way to output a list of files that were cached or restored, because Netlify already provides an official plugin named netlify-plugin-debug-cache to do exactly that. No need to re-invent the wheel!

You can add their debug plugin after this plugin in your netlify.toml. (And yes, you need a [[plugins]] line for each plugin you add.)

[[plugins]]
package = "netlify-plugin-debug-cache"

The plugin will generate a file named cache-output.json at the root of your project's publish directory. Learn more about this plugin here.

Licenses

This project is distributed under the MIT License.