WebmasterID logoWebmasterID
Crawl diagnostics

JavaScript redirects and crawling

A JavaScript redirect changes the location in script (for example via window.location) and only executes after the page is fetched and rendered. Google can follow JavaScript redirects once it renders the page, but its guidance is to prefer server-side HTTP redirects because they are processed immediately and unambiguously. JavaScript redirects add latency and depend on successful rendering.

Verified against primary sources

What this means

A JavaScript redirect navigates the browser to a new URL using script, commonly by assigning to window.location. Unlike an HTTP redirect carried in response headers, it only fires after the page is downloaded and the script executes.

Google renders pages and can therefore follow JavaScript redirects, but only as part of the rendering pass, which happens after the initial fetch. That makes the redirect later and less certain than a server-side 301/302 that is delivered before any HTML.

Why server-side is preferred

Google's documentation lists redirect types in order of preference: server-side HTTP redirects are clearest, meta refresh is acceptable, and JavaScript redirects are a fallback when the others are not possible. The reason is processing certainty and speed — an HTTP redirect needs no rendering.

JavaScript redirects also fail if the script does not run: a rendering error, a CSP that blocks the script, or a timeout can leave the crawler on the original URL. For permanent moves especially, a 301 consolidates signals far more reliably.

Diagnosing and replacing

If a JavaScript redirect is being honoured inconsistently, check whether the page renders cleanly for crawlers using the URL Inspection live test, and whether CSP or a script error prevents the redirect from running.

Where you control the server, replace JavaScript redirects with HTTP redirects. Reserve JavaScript redirects for cases driven by client state that the server cannot know, and ensure the target is reachable and indexable.

How it appears in analytics and logs

A JavaScript redirect only resolves after a crawler renders the page, so it is processed later than an HTTP redirect and depends on the script running successfully. Google can follow it but treats it as a weaker, slower routing signal.

Diagnostic use case

Diagnose why a JavaScript-based redirect is being picked up slowly or inconsistently, and decide when to migrate it to a server-side HTTP redirect for reliable crawl behavior.

What WebmasterID can help detect

WebmasterID records crawler requests to source and destination URLs server-side, so you can confirm whether crawlers actually rendered the page and followed the JavaScript redirect to the target.

Common mistakes

Privacy and accuracy notes

JavaScript redirect detection inspects your page logic, not visitors. WebmasterID treats it as a crawl-routing topic and never ties redirect logic to visitor identity.

Related pages

Sources and verification notes

Last reviewed 2026-06-24. Facts are checked against primary/official sources where available; uncertain specifics are marked “Data not yet verified” rather than guessed.