跳到正文
DEV Community· Marat Y·· 23 分鐘前AI 評分65

AI 爬蟲能否讀取 React 應用?檢查與修復方法

Can AI Crawlers See Your React App? How to Check and Fix It

AI 導讀

文章説明如何檢查 React 客戶端渲染頁面是否把內容放進首個 HTML 回應,並比較幾種修復方式。文中稱,Vercel 數據顯示,ChatGPT 和 Claude 爬蟲的請求中分別有 11.50% 和 23.84% 會抓取 JavaScript 檔案,但不會執行;Googlebot 則會渲染 JavaScript,但渲染可能延遲。

正文

Open your React app, press Ctrl+U, and look at the HTML your server actually sends. On a typical client-rendered app you'll find a title tag, a few script tags, and something like this:

<body>
  <div id="root"></div>
  <script type="module" src="/assets/index-a1b2c3.js"></script>
</body>

That's the whole page as far as the first request is concerned. Everything your visitors read, every heading, price and paragraph, gets built later by JavaScript in the browser. For people that's fine. For crawlers it depends on who's asking, and in 2026 more of the "who" is an AI system.

What crawlers actually see on a client-rendered page

Googlebot renders JavaScript, eventually. Google describes its pipeline as three phases: crawling, rendering and indexing. Pages go into a render queue, a headless Chromium executes the JavaScript, and the rendered HTML is what gets indexed (Google Search Central). It works, but rendering can lag behind crawling, and anything that fails to load during that render simply isn't there.

Most AI crawlers have historically read only the raw HTML. Vercel analysed crawler traffic across its network and found that ChatGPT's and Claude's crawlers do fetch JavaScript files (11.50% and 23.84% of their requests) but don't execute them (Vercel, "The rise of the AI crawler"). They download your bundle and then ignore what it would have built.

The picture is starting to shift, unevenly. In late September 2026 a developer reported from his own server logs that OAI-SearchBot and GPTBot began rendering JavaScript on his sites from September 25, and noted he couldn't find any announcement from OpenAI (report on Indie Hackers). By his own observation it looked like rendering was switched on only for some sites. So: maybe some bots render some of the time. That's not something to build a strategy on.

The safe conclusion hasn't changed: if content matters, it should be in the first HTML response. Then it doesn't matter which crawler renders and which doesn't.

Why this matters even if Google indexes you fine

It's tempting to stop at "Google renders it, so we're covered." Three things make that risky.

First, AI answers are a traffic source now. When someone asks ChatGPT, Claude or Perplexity which tool to use for a job, those systems lean on what their crawlers could read. A page that's an empty shell to them is a page they can't quote, however well it ranks on Google.

Second, Google's render step is a second pass. Content that only exists after JavaScript runs reaches the index later than content in the HTML, and a slow API call or a blocked script during that render means the content is missing from what Google saw.

Third, plenty of the web's plumbing never ran JavaScript in the first place: link previews in Slack, LinkedIn and X, many SEO tools, and smaller search engines. They all read the first response and move on.

How to check your site in five minutes

You don't need a special tool. A terminal and a browser are enough.

1. Look at the raw HTML. View the page source (not DevTools, which shows the live DOM) and search for a sentence you can see on screen. If it's not in the source, a non-rendering crawler won't see it either.

2. Ask for the page the way a bot would. curl lets you send any User-Agent:

curl -s -A "Mozilla/5.0 (compatible; GPTBot/1.0; +https://openai.com/gptbot)" \
  https://example.com/pricing | grep -o "<title>[^<]*</title>"

This shows what your server returns to that User-Agent. The full strings for each bot are in the vendors' docs, such as OpenAI's crawler page; for this test any string containing the bot's name will do.

3. Compare word counts. Count the visible words in the raw HTML and in the rendered page:

# raw HTML, tags stripped
curl -s https://example.com/pricing | sed -e 's/<[^>]*>//g' | wc -w

# rendered DOM from headless Chrome
google-chrome --headless --dump-dom https://example.com/pricing \
  | sed -e 's/<[^>]*>//g' | wc -w

The numbers won't match exactly, and that's fine. A gap like 40 versus 1,800 is the problem in one line.

4. Use Search Console's URL Inspection. "View crawled page" shows the HTML Google ended up with after rendering, plus any resources it couldn't load.

5. Paste the link into Slack or LinkedIn. Link previews come from crawlers that don't run JavaScript either. A generic title and no image usually means the meta tags are being added client-side.

Three ways to fix it

Approach What it means Good for Trade-off
SSR / SSG The server (or the build) produces full HTML: Next.js, React Router v7 framework mode, Astro, Nuxt New projects, teams that can change the architecture Real migration work on an existing SPA
Prerendering Bots get a cached HTML snapshot, humans get the regular app Existing SPAs, teams that can't migrate soon Another moving part: caching and bot detection
Partial fixes Static meta tags in index.html, llms.txt, a few static landing pages Quick wins on top of either Doesn't put the real page content in the HTML

If you're starting fresh, SSR or static generation is usually the cleanest answer. The hard case is the app that already exists, ships weekly, and has nobody free to move it to a new framework this quarter. That's where prerendering earns its place.

The partial fixes are worth doing regardless. Putting a real title, description and Open Graph tags straight into index.html costs an hour and fixes link previews immediately. An llms.txt file gives AI systems a plain-text map of your important pages. Neither puts your actual page content in the HTML, so treat them as extras, not the fix.

How prerendering works

The idea is simple. A headless browser loads your page, waits for the JavaScript to finish, and saves the resulting HTML. When a crawler asks for that URL, it gets the saved snapshot. Everyone else gets the normal app.

The switch usually lives in front of the app, in nginx or an edge worker, and keys off the User-Agent:

map $http_user_agent $is_bot {
    default 0;
    ~*(googlebot|bingbot|gptbot|oai-searchbot|chatgpt-user|claudebot|perplexitybot|linkedinbot|twitterbot|slackbot) 1;
}

Requests where $is_bot is 1 (and that aren't for static assets) are proxied to the prerenderer; the rest fall through to index.html as usual. You can run the renderer yourself with the open-source Prerender server and headless Chrome, or use a hosted service. Renderlix, for example, provides prerendering for AI crawlers at the nginx or Cloudflare Worker level (or through an SDK for Next.js and Express), so the React app itself stays untouched.

Two details decide whether this works well in practice. First, your app should tell the renderer when it's done: setting window.prerenderReady = false at startup and true once data has loaded stops snapshots from being taken half-way. Second, snapshots need refreshing when content changes, or bots will keep reading yesterday's prices.

Is prerendering cloaking?

It's a fair question, since bots and humans are technically served differently. Google's position is that dynamic rendering, which is what prerendering for bots is, is a workaround rather than a recommended long-term solution, because it adds complexity. It also says Googlebot generally doesn't treat it as cloaking as long as the content is similar to what users see (Google: Dynamic rendering as a workaround).

So the rule is: same content, different delivery. A snapshot of the page your users see is fine. A special keyword-stuffed version for bots is not.

Post-launch checklist

  • Bots get HTTP 200 and the full page HTML, not a redirect, a 404 or an empty shell.
  • robots.txt doesn't block GPTBot, ClaudeBot or PerplexityBot unless you mean it to.
  • The snapshot matches what users see: same headings, same prices, same text.
  • Title, description and Open Graph tags are present in the raw HTML.
  • Snapshots are refreshed when content changes, and you know how old the oldest one is.
  • Static assets (JS, CSS, images) are excluded from prerendering.

FAQ

Does Googlebot render JavaScript?
Yes. Google crawls, renders in headless Chromium, then indexes, though rendering can happen later than crawling.

Does GPTBot run JavaScript?
Historically, no: Vercel's data showed OpenAI's crawler fetching JS files without executing them. Since September 2026 there are reports of OpenAI's crawlers rendering on some sites, with no official confirmation. Plan as if they don't.

Is dynamic rendering still OK for Google?
Google calls it a workaround, not a recommended solution, but doesn't treat it as cloaking when bots and users get similar content.

Should I block AI crawlers?
That's a business decision. If you want to be cited in ChatGPT, Claude or Perplexity answers, blocking their crawlers works against you. If you block them, rendering doesn't matter for those bots.


Originally published on the Renderlix blog. This article was written by the Renderlix team. We build a prerendering service, so we've tried to keep the tool-specific part to one paragraph and give you checks you can run without us.

來源:DEV Community · dev.to