A JavaScript redirect is a script on a web page that sends the browser to a different address after the page has started to load, usually by setting window.location. It works only when the visitor, or the crawler, runs JavaScript. Google ranks it below server-side and meta refresh redirects for reliability and says to use it only when those two are not possible.
What is a JavaScript redirect? #
Most redirects happen on the server. The browser asks for a page, and the server answers with an HTTP status code such as 301 and a new address. No page content is sent at all. A JavaScript redirect is different. The server sends a normal 200 page, the browser loads it, and then a line of script moves the visitor on. The simplest version looks like this:
<script>
window.location.href = "https://example.com/new-page/";
</script>
MDN’s guide to redirections explains that this only works on clients that execute JavaScript. It also notes one strength: a script can redirect only when a condition is met, for example when a product no longer exists.
How is it different from other redirects? #
Google’s redirects and Google Search page lists the methods in order of how likely Google is to read them correctly:
| Method | Where it runs | How Google treats it |
|---|---|---|
| Server-side 301 or 308 | Server, before any page is sent | Permanent. The most reliable choice. |
| Server-side 302, 303 or 307 | Server | Temporary. |
| Meta refresh, 0 seconds | Browser, in the HTML head | Read as permanent. |
| Meta refresh, delayed | Browser | Read as temporary. |
| JavaScript location | Browser, after the script runs | Listed with permanent redirects, but only seen if rendering works. |
| Crypto redirect | A plain link with a short note | Google may or may not recognise it. |
For the fine detail of the server-side codes, see 301 vs 302, 307 and 308.
Why does it matter for search? #
Google works through script-built pages in 3 steps. It crawls, then renders, then indexes (see crawling and rendering). Its JavaScript SEO basics warns that a page can sit in the render queue for seconds or for much longer. The redirect page puts it plainly: Google runs the script after crawling, so if rendering fails, Google might never see the redirect.
That has 3 effects for a small site:
- Slower moves. A server redirect is seen on the first fetch. A script redirect waits for rendering.
- Weaker signals. If the redirect is missed, Google keeps the old page, which may show as duplicate content or as a page with almost nothing on it.
- Wasted fetches. Every old address still costs a crawl and a render, which matters on large shops with a tight crawl budget.
Why does it matter for AI answers? #
The same rule applies to any machine: a script redirect is only followed by a client that runs JavaScript. If an AI crawler reads raw HTML and does not run scripts, it will stop at the old page and never reach the new one. The facts it keeps may then be out of date, and an AI answer may link to an address you have retired. A server redirect is plain HTTP, so every client sees it. That is part of good AI crawlability.
When is a JavaScript redirect the right tool? #
There are 2 fair uses:
- No server access. Some platforms do not let you set server redirects or edit the HTML head. Google says to use a script only if you cannot do server-side or meta refresh redirects.
- Single-page apps. In a single-page application, the server returns the same shell for every address. Google’s JavaScript guide suggests a script redirect to an address where the server returns a real 404, so a missing product does not become a soft 404.
For anything else, such as a site move, a renamed category or HTTP to HTTPS, use a server redirect.
How does the browser decide which redirect wins? #
MDN sets out the order. HTTP redirects run first, because they happen before any page arrives. JavaScript redirects run next. A meta refresh runs only after the page has fully loaded, so a script will usually beat it. A script that waits for a click runs last. If you stack methods and later change only one, you can create a redirect loop. MDN advises using HTTP redirects where you can and not adding meta redirects on top.
Common mistakes #
- Using it for a site move. A full migration needs server rules. See move a website without losing traffic.
- Adding a delay. A timer that waits 5 seconds annoys people and gives crawlers more chance to miss it.
- Chains. A server redirect that lands on a page with a script redirect makes a redirect chain. Point every old address straight at the final one.
- Breaking the back button. MDN’s page on Location.replace() says it does not save the current page in session history, so the user cannot go back to it. Use replace() for a redirect, so visitors are not bounced forward again when they press back.
- Mixing signals. A canonical tag on the old page that points at itself, plus a script that sends people elsewhere, tells Google 2 different things.
- Hiding it from users only. Sending crawlers one place and people another is cloaking.
A worked example #
A small online shop sells a kettle at /kettles/steel-kettle/. The manufacturer stops making it, and the shop wants old links to land on /kettles/. The shop’s platform gives no access to server rules.
- First choice: ask whether the platform has a redirect setting. Many do, and that gives a true 301.
- Second choice: a meta refresh with a 0 second delay in the old page head, which Google reads as permanent.
- Last choice: a script in the head with
window.location.replace("/kettles/");plus a visible link to the category, so people and crawlers without JavaScript still have a way forward.
Then check it. A redirect checker should show a 200 for the old address, because the script runs in the browser, not the server. That is your clue that Google must render the page to see the move.
How to check it #
- Run the old address through our redirect checker. A server redirect shows a 301 or 308. A script redirect shows 200, with no hop. Our redirect checker guide explains each line.
- Our JavaScript SEO checker sets the served source beside the browser-built page, which shows whether the move exists only in script.
- Look at the headers with the HTTP header checker, and confirm the old page’s index status with the indexability checker.
- In Google Search Console, run URL Inspection on the old address and view the rendered page.
- Write proper rules with the redirect generator once you have server access. Ongoing checks across a whole site are coming in our JavaScript rendering check (Pro) and redirect monitor (Pro).
Questions #
Does Google follow JavaScript redirects? #
Yes, when it renders the page. Google says it might never see one if rendering fails, so it is the least reliable of the common methods.
Is a JavaScript redirect permanent or temporary? #
Google’s table lists JavaScript location under permanent redirects. A server 301 or 308 makes your intent clear without depending on rendering.
Will it pass link value? #
Google does not give a figure. Treat a server redirect as the safe way to carry link equity to the new address.
Is it bad for speed? #
Yes. The browser downloads and starts to build a page it then throws away. MDN notes that performance is hit with every redirect.
Related words #
Sources #
- Google Search Central: Redirects and Google Search, checked 25 November 2026
- Google Search Central: Understand the JavaScript SEO basics, checked 25 November 2026
- MDN: Redirections in HTTP, checked 25 November 2026
- MDN: Location.replace() method, checked 25 November 2026
Updated 25 November 2026 by URSY.
Cite this page: JavaScript redirect. URSY. Updated 25 November 2026. https://ursy.com/wiki/javascript-redirect/ · Section links
Tools for this
- LiveRedirect Checkerevery hop, 301 / 302, loopsRun the check →
- LiveLink Checkerevery link on a page: broken, redirected, internal, external, as CSVRun the check →
- LiveJavaScript SEO Checkerwhat bots that don't run JavaScript missRun the check →
- ProRedirect monitorChains, loops, 302sIn URSY Pro →
- ProJavaScript rendering checkWhat bots that don't run JavaScript missIn URSY Pro →
- ProMigration redirect mapperWhole-site old to new 301 mapIn URSY Pro →