JavaScript Redirections

Ce que a JavaScript redirection is, how Google's render pipeline treats it differently from a server-side 301, quand it's an acceptable dernier resort, and how to implement and detect un — plus où meta refresh and the History API fit.

Première publication : 27 juin 2026 · Dernière mise à jour : 3 août 2026 · Advanced
Langues
1 indice probant sur cette page

A JavaScript redirection sends utilisateurs and robots d’exploration to a nouveau URL with client-side code (window.emplacement.replace() or .href). It's the least reliable redirection type parce que Google seulement sees it après rendering — qui peut be delayed, or échouer entirely, with aucun fixed timeline soit façon. Google's official order of preference is server-side (301/302/307/308) → meta refresh → JavaScript, and its docs dire plainly: seulement utiliser JS redirections si vous pouvez't do the autre two. Une fois Google successfully interprets un, the target becomes a canonicalization signal — but that's pas a proven guarantee of identical PageRank or ranking outcomes to a 301, so treat it as a dernier resort plutôt que a like-for-like swap. Utiliser les on constrained platforms with aucun server accès, pour SPA error pages que point to a réel 404, and little sinon. Si vous doit utiliser un, utiliser window.emplacement.replace() in the <head>, drop l’URL source from votre sitemap, and point lien internes at the final destination. Meta refresh is a separate HTML-level redirection, and history.pushState()/replaceState() aren't redirections at tout.

TL;DR — A JavaScript redirection is a client-side redirection (window.location.replace(), .href, .assign()) que Google seulement processes après rendering — phase three of explorer → render → index. A server-side 301 is seen at explorer temps; a JS redirection waits on the render queue, and Google donne aucun fixed timeline pour que wait — it peut be rapide or it peut prendre a long pendant que, and rendering peut échouer outright. Google’s documented preference order is server-side → meta refresh → JavaScript, and the docs dire to utiliser JS redirections seulement quand vous pouvez’t do the autre two. Une fois Google successfully interprets un, the target becomes a permanent canonicalization signal — même Google utilisé les on leur propre blog quand nothing sinon worked — but that’s pas documented proof of identical PageRank or ranking outcomes to a 301, so they’re a dernier resort, pas a spam signal. The legitimate uses are constrained platforms with aucun server config and SPA error pages que point at a réel 404. Implement with window.location.replace() in the <head>, drop the source from votre sitemap, repoint lien internes, and confirmer Googlebot peut récupérer the JS. Meta refresh is HTML-level (0s = permanent, quelconque delay = temporary), and history.pushState()/replaceState() aren’t redirections at tout.

Ce que counts as a JavaScript redirection

Script navigation dépend on rendering and execution, so it n’est pas protocol-equivalent to an HTTP redirection. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: JavaScript redirects Processing is possible, pas an exact-timing or indexation guarantee. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: Redirects and Search

A JavaScript redirection navigates le navigateur to a nouveau URL with client-side code. The courant méthodes, and how ils differ:

  • window.location.replace("url") — navigates and removes the original URL from session history. Ce is the un to utiliser: the back button skips the redirection source au lieu de bouncing the utilisateur straight back.
  • window.location.href = "url" — navigates but garde the original in history, so the back button renvoie to the redirecting page (and peut créer a loop). document.location.href and window.location.assign("url") behave the même façon.
  • history.pushState() / history.replaceState()pas redirections. Ils rewrite the adresse bar sans quelconque navigation or HTTP signal, so robots d’exploration don’t treat les as redirections. SPAs utiliser les pour in-app URL changements; ils besoin réel <a href> liens (or réel navigations) to be crawlable.

The dividing line que matters: .replace(), .href, and .assign() tout trigger a réel document navigation (the difference entre les is seulement ce que se produit to session history), pendant que pushState()/replaceState() jamais navigate at tout — ils touch history state and the adresse bar and nothing sinon. None of the four is an HTTP 301; “redirect” ici is shorthand pour client-side navigation, pas a status code.

Meta refresh (<meta http-equiv="refresh" content="0;url=...">) is souvent lumped in with JS redirections, but it’s an HTML directive parsed avant JavaScript runs — a separate, plus reliable category, covered ci-dessous.

How Google processes a JavaScript redirection

Ce is the crux. Google’s pipeline runs in stages, and a JS redirection and a server-side redirection obtenir caught at différent ones:

  1. Explorer — Googlebot récupère l’URL and reads the raw HTML. A server-side 301/302/307/308 is seen correct ici.
  2. Render queue — pages que retourner 200 wait to be rendered. Google’s docs remarque lune page “may stay on ce queue pour a few seconds, but it peut prendre plus long que que.” Google doesn’t publish a fixed service-level timeline au-delà que, so treat the wait as unpredictable — it peut be rapide, or it peut drag — plutôt que assuming quelconque spécifique number of days or weeks.
  3. Render + index — headless Chromium runs the JavaScript. Ce is the premier moment a JS redirection exists as far as Google is concerned.

The même idea I faire on Exploration and in JavaScript SEO s’applique ici: rendering is a separate step from fetching, and anything que dépend on it inherits que delay and que risk.

And the risk is réel. Google: “Pendant que Google attempts to render every URL Googlebot crawled, rendering may échouer pour various raisons. Ce signifie que si vous définir a JavaScript redirection, Google pourrait jamais voir it si rendering of le contenu failed.” (Recherche Google Central) During the window avant the redirection is processed — and forever, si rendering fails — Google may garder the vide source page in its index.

Google’s official preference order

The redirections documentation lays out a hierarchy from la plupart to least reliable:

  1. Server-side redirections — 301/308 (permanent), 302/307 (temporary). Meilleur pour everything: seen at explorer temps, unambiguous.
  2. Meta refresh — HTML-level. A 0-second meta refresh is treated as a permanent redirection (comme a 301); quelconque delayed meta refresh is treated as temporary.
  3. JavaScript redirections — dernier resort.

Google’s words: “Seulement utiliser JavaScript redirections si vous pouvez’t do server-side or meta refresh redirections.” Redirection permanentes réussir the canonical signal to the target; temporary ones garder the original in results. (How que interacts with canonical selection is over on Canonicalization.)

Fait popularité des liens réussir via?

Google’s propre redirections documentation listes JavaScript emplacement navigation among its redirection permanenteion méthodes, and dit the target becomes the canonicalization signal une fois Google has interpreted it — so the flat “JS redirections don’t réussir PageRank” claim is faux. Ce que the documentation doesn’t establish is que the outcome is identical, immediate, or as reliable as a server-side 301 — it describes the canonical signal, pas a guarantee of matching PageRank flow, ranking, or timing. The honest framing: a 301 passes the signal at explorer temps with near-certainty; a JS redirection passes it seulement si and quand rendering succeeds, and Google doesn’t promise le résultat va match a 301’s outcome one-for-one. Que gap — pas lost equity — is the réel cost of choosing JavaScript.

Ce is aussi pourquoi JS redirections aren’t a penalty trigger on leur propre. Ils seulement become a spam problem quand they’re utilisé pour cloaking — showing robots d’exploration un page and redirecting utilisateurs to something différent, or sending mobile utilisateurs to an unrelated domain. Google’s sneaky redirections policy is à propos de que intent, pas the technique.

Quand a JavaScript redirection is the correct outil

Là are legitimate cas:

  • Constrained platforms. Some shared hosting, CDN, or CMS setups give vous aucun accès to server-side redirection rules. A JS redirection is a valid fallback — and notably, Google utilisé JS redirections on leur propre Webmaster blog parce que, as Gary Illyes put it, “que was the seulement chose we pourrait utiliser pour 1:1 redirections, and it fonctionne on Google” (OnCrawl).
  • SPA error handling. Google explicitly endorses ce: “Utiliser a JavaScript redirection to une URL pour qui le serveur responds with a 404 Code d’état HTTP.” (Recherche Google Central) A single-page app que resolves a bad route peut redirection to a réel 404 endpoint so Google processes the error correctement au lieu de indexation a soft 404.

Pour permanent URL migrations, ce is pas the outil — utiliser a 301. I faire the même point in migration de sites: JavaScript redirections are a dernier resort, and Google may jamais voir les.

Static site generators: the Hugo aliases trap

A courant surprise: Hugo’s aliases: frontmatter has historically generated meta refresh HTML pages, pas server-side 301s — and autre static generators have fait similaire choses by par défaut. Generator defaults modifier entre versions, so vérifier votre current deployed version’s réel output plutôt que assuming; si aliases: isn’t giving vous 301s, vous besoin platform-level redirection rules (Netlify _redirects, Cloudflare Workers, Vercel vercel.json) plus (on Hugo) disableAliases: true. I cover ce in detail in Hugo SEO.

Implementation meilleur practices

Si a JavaScript redirection is genuinely votre seulement option:

  • Utiliser window.location.replace(), pas .href. As Moteur de recherche Journal puts it, JS redirections “typically utiliser window.location.replace() function plutôt que window.location.href to éviter UX boucle de redirectionss” (SEJ).
  • Put it in the <head>, pas the <body>. Navigateurs parse HTML sequentially and run scripts as ils hit les, so “position JavaScript redirections in the <head> tag plutôt que <body> to minimize delay” (OnCrawl).
  • Redirection to the final destination in un hop. A JS redirection to une page que itself 301s elsewhere rend a chain; chains waste budget d’exploration and peut surface in GSC as a redirection error.
  • Supprimer l’URL source from votre XML sitemap. Sitemaps devrait liste canonical, indexable URLs — pas redirecting ones.
  • Repoint lien internes at the destination, so ils don’t route via the redirection at tout.
  • Assurez-vous Googlebot peut récupérer the JS. Si the redirection lives in an external script blocked by robots.txt, Google can’t render it and won’t voir the redirection.

How to detect JavaScript redirections

Ils don’t announce themselves comme a 301 in a header, so vous have to render:

  • A robot d’exploration with JS rendering on. OnCrawl recommends exploration with “JavaScript rendering enabled (5-second timeout minimum)”; Screaming Frog and Ahrefs Site Audit peut les deux render. Sans rendering, a JS-redirecting page simplement semble comme a normal 200.
  • Chrome DevTools. The Network tab (with “Preserve log”) montre the client-side navigation; the Redirection Chemin extension flags it aussi.
  • In Search Console, a successfully processed JS redirection montre up sous Page avec redirection — the même status as quelconque redirigé URL, qui is normal pour non-canonical sources. Que étiquette isn’t guaranteed on quelconque donné vérifier, though: it reflects whatever Google récupéré, rendered, interpreted, and canonicalized at the sampled moment, so une URL peut montrer a différent status (or aucun redirection status yet) entre checks sans que being an error on votre fin.

Ce que I’d en réalité do

Server-side premier, every temps. Meta refresh (0-second) quand vous pouvez edit HTML but pas server config. JavaScript seulement quand les deux are off the table — and alors with window.location.replace() in the <head>, a clean sitemap, and a vérifier que the redirection en réalité renders pour Googlebot. Pour anything permanent or high-value, the supplémentaire reliability of a 301 is worth almost quelconque effort to obtain.

Add an expert note

Pin an expert quote

New person? Create their unclaimed profile at /admin/experts/ → Pin a quote first.