NNext.js 中文网 GitHub

htmlLimitedBots

指定应接收阻塞式元数据的 user agent 列表。

htmlLimitedBots 配置允许你指定一个 user agent 列表,这些 user agent 应接收阻塞式元数据,而不是流式元数据。

next.config.ts
import type { NextConfig } from 'next'

const config: NextConfig = {
  htmlLimitedBots: /MySpecialBot|MyAnotherSpecialBot|SimpleCrawler/,
}

export default config
next.config.js
module.exports = {
  htmlLimitedBots: /MySpecialBot|MyAnotherSpecialBot|SimpleCrawler/,
}

默认列表#

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

  • Google 爬虫(例如 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.js
module.exports = {
  htmlLimitedBots: /MySpecialBot|MyAnotherSpecialBot|SimpleCrawler/,
}

禁用#

要完全禁用流式元数据:

next.config.ts
import type { NextConfig } from 'next'

const config: NextConfig = {
  htmlLimitedBots: /.*/,
}

export default config
next.config.js
module.exports = {
  htmlLimitedBots: /.*/,
}

版本历史#

版本变更
15.2.0引入 htmlLimitedBots 选项。
Next.js 中文网