# Avoid handling language only through cookies/JS

- Check 22.07 · International architecture · Critical
- Source: https://checklist-seo-geo.com/en/international-architecture/avoid-handling-language-only-through-cookies-js
- Find languages served by cookie, session or JavaScript on a single URL and replace them with server-rendered translated pages, in every environment.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/international-architecture/avoid-handling-language-only-through-cookies-js.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

A language handled only through cookies or JavaScript means a single URL that displays French or German depending on a cookie, a session, the browser's local storage or a translation script. Crawlers then see only one language. The task is to find these mechanisms and replace them with translated pages served under their own URLs, in the HTML returned by the server. The cookie can stay, but only to remember a choice, never to change the content of a URL.

## Why it matters

Google documents this unambiguously: it recommends distinct URLs rather than cookies or browser settings to change the language of a page. Its rendering service keeps no state from one page to the next: cookies, local storage and session storage are cleared between page loads. Googlebot therefore always arrives "fresh": without a language cookie, it receives the default version, every time. The other languages do not exist for it.

JavaScript translation adds a second problem. Google renders JavaScript, but with a delay, and only what is displayed without interaction: a translation triggered by a click on a menu is never seen. Generative engine crawlers go further in the other direction: a study published by Vercel in December 2024 found that none of the major AI crawlers observed (including OpenAI, Anthropic and Perplexity) executed JavaScript. For them, only the language of the initial HTML counts.

Finally, a URL whose content depends on a cookie creates a caching problem: a CDN or caching plugin may serve one visitor the language chosen by the previous one.

## What it improves

- **Indexing of secondary languages**: they become visible to Googlebot and Bingbot, which have no cookies.
- **Citations in AI answers**: the translated content is in the HTML read by crawlers that do not execute JavaScript. Effect not guaranteed.
- **hreflang**: it becomes possible to connect real URLs.
- **Cache reliability**: one URL, one language, one cacheable response.
- **Sharing**: a link opens the same language for everyone.

## How to check

**1. Does the content change depending on the cookie?** Find the name of the language cookie in the browser's developer tools (Application or Storage tab), then:

```bash
curl -s https://example.com/tarifs | grep -o -i '<html[^>]*lang="[^"]*"'
curl -s -H "Cookie: lang=de" https://example.com/tarifs | grep -o -i '<html[^>]*lang="[^"]*"'
```

Expected result: the same language in both cases. A different language with the cookie indicates the problem.

**2. Does the language depend on JavaScript?** Compare the initial HTML with the displayed page:

```bash
curl -s https://example.com/de/preise/ | grep -c "Preise"
```

A result of `0` while the browser displays "Preise" means the translation is applied by a script. Also check by disabling JavaScript in the browser: the text must stay in the URL's language.

**3. Does the switcher lead to URLs?** In the source code, each switcher entry must be an `<a href="/de/preise/">` link, not a button that sets a cookie or calls a function.

**4. What Google sees**: URL Inspection in Search Console, then "Test live URL" and "View tested page". The rendered HTML must be in the URL's language. See also [compare initial HTML and rendered DOM](https://checklist-seo-geo.com/en/javascript-html-rendering/compare-initial-html-rendered-dom).

## How to implement

### Before you start

The mechanisms to replace, and what replaces them:

| Current mechanism | Problem | Replacement |
|---|---|---|
| Cookie or session that chooses a URL's language | Crawlers have no cookies: only one language indexed | Language in the URL (`/de/`), cookie limited to remembering the choice |
| JavaScript machine translation widget | No translated page in the HTML | Translated pages published under their own URLs |
| Single-page application that reads the language from local storage | Client-side rendering, language invisible without execution | Language prefix and server-side or static rendering |
| Switcher using `onclick` without `href` | Crawlers do not follow the link | `<a href>` links to the equivalent page |

Prerequisite: each language has a distinct URL, see [plan a separate URL for each language version](https://checklist-seo-geo.com/en/international-architecture/plan-separate-url-each-language-version).

Legitimate use of the cookie: remembering the chosen language in order to suggest it on the next visit to the root, as a suggestion. The content of a URL must never depend on it. If you set a preference cookie, it falls within the scope of your consent management: check its status against your privacy policy.

### Apache

Versions: Apache 2.4.

Look for rules that read a language cookie:

```bash
grep -rn -i "HTTP_COOKIE" /etc/apache2/ /var/www/ --include="*.conf" --include=".htaccess"
```

A rule like this one serves two languages under the same URL and must go:

```apache
# Remove: the same URL serves German if the cookie is present
RewriteCond %{HTTP_COOKIE} lang=de
RewriteRule ^(.*)$ /de/$1 [L]
```

Without the `R` flag, this rewrite is internal: the displayed URL stays `/tarifs` while the content is German. Remove it and let the switcher point to `/de/preise/`. Reload with `sudo apachectl configtest && sudo systemctl reload apache2`.

### Nginx

Versions: Nginx 1.24 and later.

Same search:

```bash
sudo grep -rn -E "cookie_|http_cookie" /etc/nginx/
```

A `map $cookie_lang` that changes the document root or the backend under the same URL must be removed:

```nginx
# Remove
map $cookie_lang $site_root {
    default /var/www/example/fr;
    de      /var/www/example/de;
}
```

Instead, serve each language under its prefix:

```nginx
location /de/ {
    root /var/www/example;
    try_files $uri $uri/ /de/index.html;
}
```

Then `sudo nginx -t && sudo systemctl reload nginx`.

### Cloudflare

Versions: Cloudflare dashboard, all plans, November 2026.

- **Cache**: if a URL's HTML varies according to a language cookie, Cloudflare's cache may serve one visitor's language to another. With the language in the URL, the problem disappears without any extra rule.
- **Workers**: a Worker that rewrites the content according to a cookie (for example with `HTMLRewriter`) recreates the flaw. Make it route to the language URL instead of translating in place.
- After the fix, purge the cache: [`Caching > Configuration`](https://dash.cloudflare.com/?to=/:account/:zone/caching/configuration), "Purge Everything".

### WordPress

Versions: WordPress 6.8 to 7.1; WPML 5.x, Polylang 3.x.

- **Browser-side translation widgets**: some plugins, often in their free version, translate the page on the fly with JavaScript without creating URLs. Check with the test in the "How to check" section: if the translated text does not appear in the HTML returned by curl, switch to a solution that publishes translated pages under their own URLs, such as WPML, Polylang, TranslatePress or Weglot.
- **WPML and Polylang** set a language cookie, but their URLs carry the language: this cookie is harmless as long as the URL format uses directories, subdomains or domains. Polylang also uses it for its browser language detection on the homepage, which is covered in [avoid forced redirects based on browser language](https://checklist-seo-geo.com/en/international-architecture/avoid-forced-redirects-based-browser-language).
- **Themes and page builders**: check that the theme's strings (menus, buttons, footer) are translated on the server side, not injected by a script.

Purge the page cache after each change.

### Shopify

Versions: Shopify admin, all plans, November 2026.

The theme's language selector sends visitors to the URL of the chosen language, which is compliant. The risk comes from translation apps that translate the store with JavaScript in the browser, and from markets served on a shared domain: Shopify states that their content is not indexed. Give each market a subfolder or a domain and publish the languages with Translate & Adapt or an app that relies on Shopify's native languages.

### Laravel

Versions: Laravel 10 to 13.

The common pattern to replace reads the language from the session:

```php
// To replace: the same URL changes language depending on the session
App::setLocale(session('locale', config('app.locale')));
```

Replace it with the language taken from the URL, using the `SetLocale` middleware and the route prefix described in [plan a separate URL for each language version](https://checklist-seo-geo.com/en/international-architecture/plan-separate-url-each-language-version). The controller that used to change the language in the session becomes a simple link:

```php
{{-- resources/views/partials/language-switcher.blade.php --}}
<nav aria-label="{{ __('Langue') }}">
    <a href="{{ route(Route::currentRouteName(), ['locale' => 'fr'] + request()->route()->parameters()) }}" hreflang="fr" lang="fr">Français</a>
    <a href="{{ route(Route::currentRouteName(), ['locale' => 'de'] + request()->route()->parameters()) }}" hreflang="de" lang="de">Deutsch</a>
</nav>
```

With the Laravel Localization package (mcamara, version 2.x for Laravel 11 to 13), do not use the `localeSessionRedirect` or `localeCookieRedirect` middleware on their own as the source of the language: the URL must remain decisive.

### Next.js

Versions: Next.js 15 and 16.

To avoid with both routers: a single unprefixed tree, translated on the client by a context provider that reads a cookie or local storage.

#### App Router

Put the pages under `app/[lang]/` and load the translations in Server Components. The translated text is then in the initial HTML.

#### Pages Router

The `NEXT_LOCALE` cookie is only used to redirect from the root to the language prefix; the pages keep their URLs. This is acceptable if the redirect is not forced.

### React, Vue or Angular without server-side rendering

A single-page application rendered only in the browser delivers nothing but an empty shell to crawlers. Two fixes, to be combined:

1. **Language in the URL**: configure detection to read the path, and nothing else. With i18next:

```js
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

i18n
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    supportedLngs: ['fr', 'de', 'en'],
    fallbackLng: 'fr',
    detection: {
      order: ['path'],
      lookupFromPathIndex: 0,
      caches: [],
    },
  });
```

2. **Translated HTML on the server side**: static prerendering of every route in every language, or a move to a framework with server-side rendering (Next.js, Nuxt, Angular SSR). See [prefer SSR/SSG for critical content if relevant](https://checklist-seo-geo.com/en/javascript-html-rendering/prefer-ssr-ssg-critical-content-if-relevant).

### Nuxt

Versions: Nuxt 3.x and 4, @nuxtjs/i18n module 9 and 10.

With `@nuxtjs/i18n`, the `no_prefix` strategy serves every language under the same URLs and relies on a cookie: switch to `prefix_except_default` or `prefix`. Nuxt's server-side rendering then puts the translated text in the initial HTML.

## Common mistakes

- **Believing Googlebot keeps the cookie** set by the first page: it starts again with no state at every load.
- **Internal rewrite based on the cookie**: the URL does not change, the content does.
- **A machine translation widget** presented as a multilingual site.
- **A language switcher built as a JavaScript button** without `href`.
- **Local storage as the source of truth** for the language of a single-page application.
- **A shared cache on pages that vary by cookie**: visitors served in the wrong language.
- **Testing while logged in with your own cookies**: always test in a private window and with curl.

## Frequently asked questions

### Does Google see content translated through a language cookie?

No, in practice. Google's rendering service clears cookies, local storage and session storage between page loads. Googlebot therefore always receives the version served without a cookie, usually the default language. The other languages, served under the same URL depending on the cookie, are neither crawled nor indexed. Give each language its own URL.

### Is a translation widget such as Google Translate enough for multilingual SEO?

No. A widget that translates the page in the browser creates no translated page: the HTML stays in the original language, with no URL of its own for each language. Search engines have nothing to index in the other languages, and crawlers that do not execute JavaScript only see the original. To be found in a language, publish reviewed, translated pages under their own URLs.

### Can you keep a cookie to remember the chosen language?

Yes, if it is only used to remember a preference, for example to suggest the right language on the next visit to the homepage. The content of a given URL must never change according to this cookie. Prefer a suggestion to a forced redirect, and handle this cookie in your consent management if it is not strictly necessary.

### Do AI crawlers read translations done in JavaScript?

Most of the time, no. A study published by Vercel at the end of 2024 found that the major AI crawlers observed, including those of OpenAI, Anthropic and Perplexity, did not execute JavaScript. A translation applied by a script remains invisible to them, and they read the language of the initial HTML. Crawler behavior changes over time: serve the translated text in the server's HTML so you do not depend on any of them.

## Resources

- [Google Search Central: Managing multi-regional and multilingual sites](https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites?hl=en)
- [Google Search Central: Fix Search-related JavaScript problems](https://developers.google.com/search/docs/crawling-indexing/javascript/fix-search-javascript?hl=en)
- [Google Search Central: Understand JavaScript SEO basics](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics?hl=en)
- [Vercel: The rise of the AI crawler (December 2024)](https://vercel.com/blog/the-rise-of-the-ai-crawler)
- [i18next: browser language detector](https://github.com/i18next/i18next-browser-languageDetector)
- [Next.js: internationalization](https://nextjs.org/docs/app/guides/internationalization)

Next steps: [Provide a crawlable language switcher](https://checklist-seo-geo.com/en/international-architecture/provide-crawlable-language-switcher) and [Test without cookies](https://checklist-seo-geo.com/en/development-accessibility-language/test-without-cookies).
