Baron Munchausen’s Crawl Test Lab

JavaScript Redirect Example: What Crawlers See

My postilion's horn froze with every tune inside it and played them all only when the kitchen fire warmed it, just like this door, which opens only for those who run the stove.

The short answer

What it is
A JavaScript redirect uses a script in the page to send the browser to another URL, often through location.href or location.replace(). The server returns a 200 status for the first page.
Why it matters
A crawler that does not run scripts sees a thin page and never finds the target. Even crawlers that render pages must do extra work, and the signal is less direct than a server redirect.
How a crawler should report it
Flag the page as a JavaScript redirect when its title starts with "Redirecting", or when it has under 50 words and an inline script that sets location or calls location.replace(). A script that only reads location.href does not count.
Live examples
The Baron hanging from a rope below the Moon.
Fig. 42. The way up appears only once the rope runs.

What crawlers see before a script sends the visitor away

A JavaScript redirect takes place after the browser has loaded a page and run its script. A typical one is window.location.replace("/new/"). It often appears when teams cannot edit server rules, when a single-page app handles routing, or when a redirect depends on data found only in the browser. Marketing pages and link shorteners also use them, in some cases to run tracking code first.

In a browser, the user sees a blank or short page, and then the new one. Setting location.href adds the first page to the history, so the back button can trap people. Using location.replace() avoids that. Slow scripts make the delay easy to notice, and a script error can leave the visitor stuck on the empty first page.

Google can render pages and follow these redirects, but its documentation says to use them only when a server redirect or meta refresh is not an option. Rendering can happen later than the first crawl, and a blocked or failed script means no redirect at all. Many other bots do not run scripts. They index the short page that holds the script, or they skip it as thin content.

To detect one, compare the raw HTML with the rendered page. A crawl without rendering can look for a title that starts with "Redirecting", or for a very short page with an inline script that sets location. A rendering crawl can compare the start URL with the final URL. To fix it, move the redirect to the server or CDN and use a 301. In an app, do the routing on the server where you can, and keep a plain link in the page as a backup.