Build caching
Improve Pages build times by caching dependencies and build output between builds with a project-wide shared cache.
The first build to occur after enabling build caching on your Pages project will save to cache. Every subsequent build will restore from cache unless configured otherwise.
When enabled, the build cache will automatically detect and cache data from each build. Refer to Frameworks to review what directories are automatically saved and restored from the build cache.
Build caching requires the V2 build system or later. To update from V1, refer to the V2 build system migration instructions.
Pages will cache the global cache directories of the following package managers:
Package Manager | Directories cached |
---|---|
npm ↗ | .npm |
yarn ↗ | .cache/yarn |
pnpm ↗ | .pnpm-store |
bun ↗ | .bun/install/cache |
Some frameworks provide a cache directory that is typically populated by the framework with intermediate build outputs or dependencies during build time. Pages will automatically detect the framework you are using and cache this directory for reuse in subsequent builds.
The following frameworks support build output caching:
Framework | Directories cached |
---|---|
Astro | node_modules/.astro |
Docusaurus | node_modules/.cache , .docusaurus , build |
Eleventy | .cache |
Gatsby | .cache , public |
Next.js | .next/cache |
Nuxt | node_modules/.cache/nuxt |
The following limits are imposed for build caching:
- Retention: Cache is purged seven days after its last read date. Unread cache artifacts are purged seven days after creation.
- Storage: Every project is allocated 10 GB. If the project cache exceeds this limit, the project will automatically start deleting artifacts that were read least recently.
To enable build caching :
- Navigate to Workers & Pages Overview ↗ on the Dashboard.
- Find your Pages project.
- Go to Settings > Build > Build cache.
- Select Enable to turn on build caching.
The build cache can be cleared for a project if needed, such as when debugging build issues. To clear the build cache:
- Navigate to Workers & Pages Overview ↗ on the Dashboard.
- Find your Pages project.
- Go to Settings > Build > Build cache.
- Select Clear Cache to clear the build cache.