简体   繁体   中英

Is Nextjs reading cache form .next/server/pages/ when using ISR and is it possible to serve it from a CDN?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM