1

I want to deploy a next project outside of Vercel and am confused how cache is working. When accessing the url for a page with ISR enabled I can confirm the db is in fact not accessed before the revalidate period isn't over but

First question : The generated page seems to live in .next/server/pages/mypage.html (and mypage.json) however when checking the devtools after requesting the page's url I can only see multiple requests to .next/static/* and .next/static/chunks/pages/* which seems to be files generated at build time that don't know anything about what has been regenerated by ISR when accessing the database, I can't find anything related to .next/server/pages. Can someone explain me that ?

Second question : If it's accessed from .next/server is it possible to cache through a CDN since NextJS' docs advice just to host .next/static on the CDN ?

The exact configuration for uploading your files to a given CDN will depend on your CDN of choice. The only folder you need to host on your CDN is the contents of .next/static/, which should be uploaded as _next/static/ as the above URL request indicates. Do not upload the rest of your .next/ folder, as you should not expose your server code and other configuration to the public.

https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix

Thanks in advance.

1
  • You should also see a document being fetched (the HTML page), that's the HTML (re)generated on the server by ISR. Only assets (_next/static/) should be served by the CDN. Commented Jan 7, 2022 at 18:24

1 Answer 1

0

Serving without hitting the front of the NextJS app and instead pointing to its own internal cache defeats the ISG Setup in my understanding.

Consider the following flow:

  1. Your CDN hits the ./server folder with a ISG generated page which was generated
  2. CMS Makes an update and your CDN is not wired to receive NextJS updates
  3. Next uses and updates the current page in the ./server with a corresponding update.
  4. Your CDN has no way of knowing unless you exactly made an update 60s earlier when the CDN expiry is set to apply.

Point to the front of the app not to the temporary storage in the /server folder that Next uses to maintain ISG. Of course, this does not apply to /public or /static folders which host the JS and you can front via CDN

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.