AIFeed

Vercel CDN 为框架新增缓存绕过规则

AI summary

框架现在可以添加 afterCacheBypass 规则,根据请求头、缓存响应头或两者兼有来决定提供缓存页面还是绕过缓存。绕过规则通过 Build Output API 设置;Vercel 按顺序检查规则,命中则绕过缓存并调用函数,响应带 x-vercel-cache: BYPASS,未命中则提供缓存页面。规则仅适用于预渲染页面,不适用于 API 路由或服务端渲染页面。Next.js 是首个使用这些规则的框架,此前对部分预渲染页面会为 Bingbot、Slackbot 等受限机器人的每个请求绕过缓存,Next.js 16.5 仅在元数据缺失时绕过,除升级外无需额外配置。

Translation(model translation, not the source's own text)

Vercel CDN 为框架新增缓存绕过规则

框架现在可以添加 afterCacheBypass 规则,根据来自请求、缓存响应或两者的 header 来提供或绕过缓存页面。

绕过规则通过 Build Output API 设置,框架可以用它来生成带有 Vercel Functions、路由和缓存等平台功能的 Vercel 部署。


        {  "version": 3,  "afterCacheBypass": [    {      "name": "HTML Limited Bots",      "hasAll": [        {          "type": "request.header",          "key": "user-agent",          "value": { "re": "Bingbot|Discordbot|Slackbot|Twitterbot|WhatsApp" }        },        {          "type": "cache.response.header",          "key": "x-has-head-metadata",          "value": { "eq": "0" }        }      ]    }  ]}
      

当缓存页面缺少 metadata 时,为受 HTML 限制的爬虫绕过缓存

Vercel 按顺序检查规则。如果某条规则匹配,Vercel 会绕过缓存并调用函数,响应会带有 x-vercel-cache: BYPASS 返回。如果没有规则匹配,Vercel 则提供缓存页面。规则仅适用于预渲染页面,不适用于 API 路由或服务端渲染页面。

Next.js 是首个使用这些规则的框架。此前,在部分预渲染的页面上,Next.js 会对来自 Bingbot 和 Slackbot 等受 HTML 限制的爬虫的每个请求都绕过缓存。这些爬虫需要完整的 <head> metadata,而 Next.js 无法判断缓存页面是否包含它。Next.js 16.5 仅在 metadata 缺失时才绕过缓存,除升级外无需任何配置。在 nextjs.org 上,这类请求中现在有超过 70% 是缓存命中。

阅读 afterCacheBypass 文档以配置你的第一条规则。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Vercel Blog
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗