Caching next.js images

Hi Alexander_Johansson,

I’ve looked into the Next docs, and its Image Component and Image Optimization - Caching section mentions that images generated by next/image are generated during runtime and cached in <distDir>/cache/images.

Any local files created during runtime will be reset on every deploy unless you create a persistent disk (Render docs) for your service. This disk will persist from deploy to deploy, so is a great way to maintain a cache.

There may also be a way to pregenerate those images during the build step, which would allow you to avoid needing a persistent disk, but I’m not familiar enough with Next to know if that’s a supported process.

Hey, thanks for the response dan

I’ve added a cache dir as follows `

But it still stays at 0GB so I think it’s not working. Is the project really installed at / or do you have like a /project folder or something?

Connected with SSL and manually navigated to the folder and did pwd which shows /opt/render/project/src/.next/cache/images - trying that now.

It seemed to have to mount /opt/render/project/src/.next/cache/images.

To your other point, Next.js recommends you to do shared build cache in case you want to speed up incremental builds & do images there. Would this be possible? Where on the server is the build generated (if it is on the same server since it says “Uploading build…” at the end of each)

Hey there- that’s a good point. I don’t believe this is possible right now, but we have a feature request you can vote on that I believe would allow this: Specify additional directories to cache after build | Feature Requests | Render. If you vote on this, you’ll be updated when we have any news.

Cool, yeah, I can’t really put all the images in the build right now without it as then it’d take ages to do the build on every push