A JavaScript redirect is a redirect that the browser carries out with a script, usually by setting window.location. The server first delivers an ordinary page with status 200. The visitor only reaches the new URL once the script has run.
How does it differ from an HTTP redirect?
With an HTTP redirect (301, 302, 307, 308) the information sits in the status code and the Location header. With a JavaScript redirect it sits in the page’s code, so a crawler only sees it after rendering the page. MDN names two limits of this method. It works only on clients that execute JavaScript, and it cannot be used for all resource types, for example images. In return it allows conditions, such as redirecting only if some check passes.
MDN also describes the order of execution. HTTP redirects run first, JavaScript redirects next, and <meta> refresh redirects afterwards, since they fire after the page has loaded.
| Type | Permanent or temporary? | Request method | Effect in Google | How reliably Google detects it |
|---|---|---|---|---|
| 301 Moved Permanently | permanent | POST may become GET when followed | Signal that the target should become canonical | most reliable (server-side) |
| 308 Permanent Redirect | permanent | preserved | same as 301 | most reliable (server-side) |
| 302 Found | temporary | POST may become GET when followed | not used as a canonical signal for the target; other signals can still get it indexed | most reliable (server-side) |
| 307 Temporary Redirect | temporary | preserved | same as 302 | most reliable (server-side) |
| Meta refresh, instant (0 s) | permanent | – (redirect inside the HTML, no 3xx status code) | same as 301 | after server-side redirects |
| Meta refresh, delayed (> 0 s) | temporary | – (redirect inside the HTML, no 3xx status code) | same as 302 | after server-side redirects |
| JavaScript (location) (this term) | permanent | – (redirect in the browser) | same as 301, but only if Google renders the page | least reliable: if rendering fails, Google may never see it |
Google orders redirect types by how likely it is to interpret them correctly: server-side redirects first, JavaScript last. Request-method behaviour is defined in RFC 9110 (section 15.4). Sources: Google Search Central: Redirects and Google Search (last updated 2026-04-14); Google Search Central: How to specify a canonical URL (redirects as canonical signal); RFC 9110: HTTP Semantics, 15.4 Redirection 3xx. Last checked: .
What does Google say?
Google’s redirect documentation lists the JavaScript location redirect among the permanent redirect types, together with 301, 308 and meta refresh with 0 seconds. The table is ordered by how likely Google is to interpret the redirect correctly, and server-side redirects come first. Google advises using JavaScript redirects only if you cannot do server-side or meta refresh redirects.
Google’s JavaScript SEO basics mention one intended use. In client-side rendered apps where meaningful HTTP status codes are hard to send, a JavaScript redirect to a URL that returns 404 (for example /not-found) avoids soft 404 errors.
Example
<script>
window.location.href = "https://example.com/new-page/";
</script>
The server-side equivalent in nginx:
return 301 https://example.com/new-page/;
Common mistakes
- A JavaScript redirect is used where a server-side 301 is possible.
- JavaScript, meta refresh and HTTP redirects are active at the same time. MDN advises against mixing them, because differences can cause an infinite loop.
Sources
- Redirects and Google Search – Google Search Centraldevelopers.google.com
- JavaScript SEO basics – Google Search Centraldevelopers.google.com
- Redirections in HTTP – MDN Web Docsdeveloper.mozilla.org
Last updated: