跳到内容
配置next.config.jshtmlLimitedBots

htmlLimitedBots

htmlLimitedBots 配置允许您指定一个用户代理列表,这些代理应接收阻塞元数据而不是流式元数据

next.config.ts
import type { NextConfig } from 'next'
 
const config: NextConfig = {
  htmlLimitedBots: /MySpecialBot|MyAnotherSpecialBot|SimpleCrawler/,
}
 
export default config

默认列表

Next.js 包含一个默认的 HTML 限制机器人列表,包括:

  • 谷歌爬虫(例如 Mediapartners-Google、AdsBot-Google、Google-PageRenderer)
  • Bingbot
  • Twitterbot
  • Slackbot

查看完整列表这里

指定 htmlLimitedBots 配置将覆盖 Next.js 的默认列表。但是,这是高级行为,对于大多数情况来说,默认值应该足够了。

next.config.ts
const config: NextConfig = {
  htmlLimitedBots: /MySpecialBot|MyAnotherSpecialBot|SimpleCrawler/,
}
 
export default config

禁用

完全禁用流式元数据

next.config.ts
import type { NextConfig } from 'next'
 
const config: NextConfig = {
  htmlLimitedBots: /.*/,
}
 
export default config

版本历史

版本更改
15.2.0引入了 htmlLimitedBots 选项。