[英]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.我想在 Vercel 之外部署下一个项目,但对缓存的工作方式感到困惑。 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在启用 ISR 的页面访问 url 时,我可以确认在重新验证期未结束之前实际上未访问数据库,但是
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.第一个问题:生成的页面似乎存在于.next/server/pages/mypage.html(和mypage.json)但是在请求页面的url后检查devtools时我只能看到对.next/static/*的多个请求和.next/static/chunks/pages/* 这似乎是在构建时生成的文件,对访问数据库时 ISR 重新生成的内容一无所知,我找不到与 .next/server/ 相关的任何内容页。 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?第二个问题:如果它是从 .next/server 访问的,是否可以通过 CDN 进行缓存,因为 NextJS 的文档建议只是针对 CDN 上的 host.next/static ?
The exact configuration for uploading your files to a given CDN will depend on your CDN of choice.将文件上传到给定 CDN 的确切配置取决于您选择的 CDN。 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.您需要在 CDN 上托管的唯一文件夹是 .next/static/ 的内容,如上述 URL 请求所示,应将其上传为 _next/static/。 Do not upload the rest of your.next/ folder, as you should not expose your server code and other configuration to the public.请勿上传 your.next/ 文件夹的 rest,因为您不应将您的服务器代码和其他配置暴露给公众。
https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix 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.在我的理解中,不打到 NextJS 应用程序的前端而是指向它自己的内部缓存来服务会破坏 ISG 设置。
Consider the following flow:考虑以下流程:
./server
folder with a ISG generated page which was generated您的 CDN 使用生成的 ISG 生成页面./server
文件夹./server
with a corresponding update. Next 使用和更新./server
中的当前页面并进行相应的更新。 Point to the front of the app not to the temporary storage in the /server
folder that Next uses to maintain ISG.指向应用程序的前面,而不是Next 用于维护 ISG 的/server
文件夹中的临时存储。 Of course, this does not apply to /public
or /static
folders which host the JS and you can front via CDN当然,这不适用于托管 JS 的/public
或/static
文件夹,您可以通过 CDN 前端
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.