跳到內容
配置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 選項。