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:
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.