Unable to Cache NextJS Builds

I’m trying to follow NextJS caching best practices defined here, but it looks like there’s no common playbook to achieve this via Cloudflare Pages. I also can’t see to sort this out myself via the build configuration options available in the UI.

In short, I would like to find some way to cache the following folders across CI builds:

  • node_modules
  • .next/cache

Is this currently possible in Cloudflare Pages?

It is not currently possible to cache anything between Pages runs.

1 Like

Caching node_modules and anything other then the public/ folder (outputfolder) is like @Jake1st stated not possible. Thats also one of the reasons I don’t use Cloudflare Pages anymore. But there is a way to speed up buildtime.

Creating the node_modules folder and unzipping all the dependencies can really take way to long specially at big projects. Therefore I tried to at least improve the buildtime by using YARN in version >2.0.0 since it supports PnP (Plug and Play) where you dont need to unzip any of the dependencies and can access all the files directly. which saves a lot of writes, which specially comes handy as a lot of Inodes would need to be created since they often contain a lot of small files which are delaying the build process.

You would still need to download all the dependencies but never unzip them, also you can just start using them right away. For me it speed up the buildprocess by about 50% which in my case is a big win, but wasn’t enough to use Pages since still too slow for me and a lot of features are missing.

Anyway this might help speeding up the build time since caching them is not possible at least it will not delay your build time by as much as before.

1 Like

Got it, thanks to both of you for the guidance. Pretty disappointed to hear this is not supported at this time, but Pages is a pretty young product so perhaps it’ll come some day soon.

I’ll keep this thread open for now in case others are looking for similar features.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.