JavaScript redirects vs 301: what Google and AI crawlers follow
JavaScript redirects and meta refresh vs server-side 301s: what Google documents, why crawlers that skip JavaScript never follow JS redirects, and how to fix them.
By Crawlito · Updated 7 min read
In short
- Google recommends a permanent server-side redirect whenever possible and says to use JavaScript redirects only if server-side or meta refresh redirects are impossible.
- Google only sees a JavaScript redirect after rendering, and says it might never see it if rendering fails.
- Google treats an instant meta refresh as a permanent redirect and a delayed one as temporary.
- A crawler that does not run JavaScript receives the old page with a 200 status and never reaches the new URL.
- Test redirects with curl: a real redirect shows a 3xx status and a Location header before any HTML is sent.
On this page
- The three kinds of redirect
- What Google documents about each type
- Why AI crawlers do not follow JavaScript redirects
- Common places JavaScript redirects hide
- Permanent or temporary: picking the right status code
- How to test a redirect
- How to replace JavaScript redirects with server-side ones
- Frequently asked questions
- Check what your old URLs return
A server-side 301 is a redirect every crawler understands, because it is in the HTTP response before any HTML arrives. A JavaScript redirect only exists after a browser runs the page's scripts, so crawlers that do not execute JavaScript never see it: they get the old page, with a 200 status, and stop there. A meta refresh sits in between: it is in the HTML, Google documents how it treats it, but other crawlers may or may not act on it.
Google's own guidance ranks them the same way: use a permanent server-side redirect whenever you can, meta refresh if you cannot, and JavaScript only as a last resort. This guide explains why, what each crawler receives, and how to find and replace JavaScript redirects on your site.
The three kinds of redirect
| Type | Where it lives | Example | Seen by crawlers that skip JavaScript |
|---|---|---|---|
| Server-side (301, 308, 302, 307) | HTTP status line and Location header | HTTP/1.1 301 + Location: /new | Yes |
| Meta refresh | <meta http-equiv="refresh"> in the HTML head | content="0; url=/new" | Depends on the crawler |
| JavaScript | A script that changes window.location | window.location.replace("/new") | No |
A server-side redirect looks like this on the wire:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/new-pageA meta refresh:
<meta http-equiv="refresh" content="0; url=https://www.example.com/new-page">A JavaScript redirect:
<script>
window.location.replace("https://www.example.com/new-page");
</script>The response for the last two is usually 200 OK, with the old page's HTML. Everything depends on what the client does with that HTML.
What Google documents about each type
Google's page on redirects and Google Search is direct. It recommends "a permanent server-side redirect whenever possible" and says a server-side redirect "has the highest chance of being interpreted correctly by Google". On the other two:
- Meta refresh. Google interprets an instant meta refresh (one that fires as soon as the page loads) as a permanent redirect, and a delayed one (after a number of seconds) as temporary. It calls meta refresh a viable alternative only when server-side redirects are not possible on your platform.
- JavaScript. "Only use JavaScript redirects if you can't do server-side or meta refresh redirects." Google executes JavaScript in its Web Rendering Service after crawling, so "if you set a JavaScript redirect, Google might never see it if rendering of the content failed."
Rendering is also not immediate. Google's JavaScript SEO basics says pages wait in a render queue that can take "a few seconds, but it can take longer than that". So even when Googlebot follows a JavaScript redirect, it does so later than it would follow a 301, and the old URL may be processed in the meantime.
Google also uses a JavaScript redirect deliberately in one case: for single-page apps, it suggests redirecting a missing route to a URL that returns a real 404, as a way to avoid soft 404s. That is a workaround for client-side routing, not a model for moving content. Our guide to SPA 404 status codes covers it.
Why AI crawlers do not follow JavaScript redirects
Most AI crawlers fetch the HTML and read it without running scripts. None of the major AI operators (OpenAI, Anthropic, Perplexity) document JavaScript execution for their crawlers, and our article on whether AI crawlers run JavaScript summarises what is known. Google itself notes that "not all bots can run JavaScript".
For a JavaScript redirect, that has a specific consequence. The crawler requests /old-page, receives a 200 with the old page's HTML, and stores whatever text is there. If the old page is now an empty template whose only job is to redirect, the crawler has an empty page. It never requests /new-page, so the content you moved may not be fetched through that path at all.
Meta refresh is less clear. Some HTML parsers act on it, others ignore it, and the AI operators do not document their handling. Do not rely on it for anything that matters.
Common places JavaScript redirects hide
- Single-page app routers that "redirect" by pushing a new route after the app loads. The server returns the same shell for every URL.
- Geo and language redirects that read
navigator.languageor call an IP lookup API, then send visitors to/de/or/fr/. Our guide to multilingual sites explains why server-side or link-based language selection works better. - Login checks that bounce visitors to
/loginwhen a token is missing. A crawler sees the protected page's shell, not the login page. - Website builders and landing page tools that offer a "redirect" setting implemented as a script.
- Leftovers from migrations, such as old pages kept alive with a one-line
location.hrefscript because the server config was not accessible at the time. - Hosting without redirect support, for example a static bucket or GitHub Pages without a redirect plugin, where meta refresh or JavaScript is the only option.
Permanent or temporary: picking the right status code
Once the redirect is on the server, the status code still matters. Google's documentation splits them into two groups:
| Status | Meaning | Google's treatment |
|---|---|---|
| 301, 308 | Moved permanently | Followed, and used as a signal that the target should be canonical |
| 302, 303, 307 | Found / see other / temporary redirect | Followed, but not used as a signal that the target is canonical |
Use a permanent redirect when content has moved for good: a renamed page, a merged article, a domain change. Google's advice is to use it "when you're sure that the redirect won't be reverted". Use a temporary one for short-lived cases, such as sending visitors to a seasonal page and back. A common mistake is the opposite: frameworks and plugins that default to 302 for every redirect, so a site migration made of temporary redirects leaves the old URLs as the canonical ones for longer than necessary.
The difference between 301 and 308 (and between 302 and 307) is only whether the client may change the request method, for example from POST to GET. For pages that crawlers fetch with GET, they behave the same.
How to test a redirect
Ask the server directly and look at the status and headers:
curl -sI https://www.example.com/old-page | grep -iE "^HTTP|^location"A real redirect returns a 3xx status and a Location header. If you get 200 and no Location, the redirect, if there is one, happens in the HTML or in JavaScript. Look for it:
curl -s https://www.example.com/old-page | grep -iE 'http-equiv="?refresh|location\.(href|replace|assign)|window\.location'To follow a whole chain and see each hop:
curl -sIL https://www.example.com/old-page | grep -iE "^HTTP|^location"For Google, the URL Inspection tool in Search Console shows which URL Google considers canonical and whether the page was redirected. For the broader picture across a site, a crawler that does not render JavaScript (most desktop SEO crawlers can be set to "text only") will list every URL that returns 200 where you expected a redirect.
How to replace JavaScript redirects with server-side ones
Move the redirect to the first layer that can answer the request: CDN, web server or application.
Nginx:
location = /old-page {
return 301 https://www.example.com/new-page;
}Apache (.htaccess):
Redirect 301 /old-page https://www.example.com/new-pageNext.js (next.config.js):
module.exports = {
async redirects() {
return [
{ source: "/old-page", destination: "/new-page", permanent: true },
];
},
};With permanent: true, Next.js sends a 308, which Google treats as permanent like a 301. In App Router code, redirect() sends a 307 by default; use permanentRedirect() for a 308. Our guide to 301, 302, 307 and 308 redirects compares the codes.
Netlify (_redirects file):
/old-page /new-page 301Cloudflare: a Single Redirect or Bulk Redirect rule returns the 301 at the edge before the request reaches your origin.
When you cannot change the server at all, use an instant meta refresh as a fallback, add a rel="canonical" link to the new URL, and include a plain HTML link to the new page in the body so any crawler that reads the HTML can still follow it:
<head>
<meta http-equiv="refresh" content="0; url=https://www.example.com/new-page">
<link rel="canonical" href="https://www.example.com/new-page">
</head>
<body>
<p>This page has moved to <a href="https://www.example.com/new-page">the new page</a>.</p>
</body>After the change, update internal links to point straight at the new URL so crawlers do not need the redirect at all, and keep redirect chains to one hop. Our guide to website migrations for AI search has a full checklist for larger moves.
Frequently asked questions
Does Google follow JavaScript redirects?
Yes, when rendering succeeds. Google executes JavaScript after crawling, so it sees the redirect later than a server-side one, and Google says it might never see it if rendering fails.
Is a meta refresh as good as a 301?
Not quite. Google treats an instant meta refresh as permanent, but recommends it only when server-side redirects are impossible, and other crawlers do not document consistent handling.
Do AI crawlers follow 301 redirects?
The operators do not publish detailed redirect handling, but a server-side redirect is part of the HTTP response that any HTTP client can follow, and RFC 9309 expects crawlers to follow redirects for robots.txt. JavaScript redirects are the ones a crawler that skips scripts cannot see.
Is a JavaScript redirect considered a sneaky redirect?
Not by itself. Google's spam policies target redirects that show users and search engines different content with intent to deceive. A JavaScript redirect that sends everyone to the same new page is a technical choice, just a weaker one than a 301.
Check what your old URLs return
Redirects that only work in a browser are easy to miss because they look fine when you click through. Run the free check on an old URL to see the status code and content a crawler receives.
Filed under Rendering and content. Topics: javascript, rendering, http-status, ai-crawlers, migration