简体   繁体   English

Nextjs 是否在使用 ISR 时读取缓存 form.next/server/pages/ 并且是否可以从 CDN 提供它?

[英]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:考虑以下流程:

  1. Your CDN hits the ./server folder with a ISG generated page which was generated您的 CDN 使用生成的 ISG 生成页面./server文件夹
  2. CMS Makes an update and your CDN is not wired to receive NextJS updates CMS 进行更新,您的 CDN 未连接到接收 NextJS 更新
  3. Next uses and updates the current page in the ./server with a corresponding update. Next 使用和更新./server中的当前页面并进行相应的更新。
  4. Your CDN has no way of knowing unless you exactly made an update 60s earlier when the CDN expiry is set to apply.您的 CDN 无法知道,除非您在 CDN 到期设置为适用时提前 60 秒进行了更新。

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.

相关问题 如何利用浏览器缓存并从具有子域的无cookie域提供服务? (与CDN) - How to leverage browser cache and serve from a cookieless domain with a subdomain? (with cdn) 从ISR刷新缓冲区缓存 - Flushing buffer cache from ISR 将工作箱与CDN一起使用时,缓存存储为空 - Cache storage is empty when using workbox with CDN 使用Symfony 2时OVH CDN缓存错误 - OVH cdn cache bug when using symfony 2 如何在 Next.js 中不选择进入 ISR 来防止静态生成的页面被缓存 - How to prevent statically generated pages from being cached without opting into ISR in Next.js CDN 边缘服务器上的缓存未命中 - Cache miss at a CDN edge server LINQ-To-SQL-是否可以缓存GetTable或从存储库提供它? - LINQ-To-SQL - Is it possible to cache GetTable or serve it from repository? 使用 lighttpd 为 wp-super-cache 创建的缓存/html 页面提供服务 - serve cache/html pages created by wp-super-cache using lighttpd 缓存破坏了本地浏览器缓存,但确保来自Azure CDN而非源服务器的响应(Web角色) - Cache busting a local browser cache but ensuring response from Azure CDN and not from origin server (Web Role) 使用CDN缓存部分网页 - Using CDN to cache parts of a webpage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM