Why would a translation be sent to someone in another language if the site negotiated the language in the request header and cached it?

📅 2026-10-11 👁️ 12

After the site with language negotiation in the request header adds caching, the translation is sent to visitors in another language, and the cause is almost always the same: the cache key only contains the address and method, without the language as an influencing factor.MDN defines Vary as exactly this: The response header describes that part of the request information, other than the method and URL, that affects the response content;The Vary header ensures that responses are cached based on the listed header fields, the most common use is to construct cache keys during content negotiation. Without this declaration, the intermediate layer will treat the translation received by the first visitor as the standard answer for the address.

The default cache key only considers the address and method

The basis for determining whether the cache hit is the cache key. By default, it consists of the request method and target address, plus some fragments of the path at most.

Content negotiation destroyed this premise. The same address, because the value of Accept-Language in the request header is different, the server generates completely different text. From the perspective of caching, it is two requests with the same key, so the second one directly uses the response of the first one.

The characteristics of this kind of problem are very stable: the local direct connection to the source station is normal, and problems occur after connecting to the cache or acceleration node; after clearing the cache once, it is normal for a short time, and then it starts to occur again; people with different browser settings see the same language. If any two of these three occur, it should be suspected of the cache key first, rather than the translation logic.

What is missing when negotiating language

What is missing is not the translation ability, but 'putting influencing factors into the response'.

When the server decides which language to return, it reads the request header; but the response itself does not tell the downstream 'my content depends on this header'. This is a one-way information loss: the program knows, but the cache does not know.

Vary is the mechanism to fill in this information. After writing it as a header containing language-related information, the cache will store copies according to the different values of this field, and the hit rate will decrease, but it will not send the wrong one.

There is a more thorough way to take a value: When Vary takes an asterisk, it means that there are other factors affecting the generation of the response, which is equivalent to the response being uncachable. This approach is honest but costly, and is generally only used when it is indeed impossible to determine the influencing factors.

It is especially important to pay attention to the consistency of the value. All responses of the same URL should use the same Vary value, including unmodified responses and default or error responses. Writing it only on successful pages and not on error pages will cause two declared objects to exist in the cache, making the behavior more difficult to predict than not writing it.

How should it be supplemented in the response header?

Write in three steps when landing.

The first step, for any address generating the text based on the language header, a language-related statement should be added. If negotiation of compression method is also done, both should be listed together, because the reason for hitting the wrong version separately is the same.

The second step, fix the negotiation rules. The language matching should have a clear order, such as precise language first, then language family next, and finally default language, rather than 'which header comes first'. When the rules are unstable, even if the cache is correct, the same user may get different translations twice when visiting twice.

The third step is to provide an explicit entry for optional languages. Relying on the request header for judgment, users actually cannot actively choose; providing a clickable language switch and allowing the selection result to fall on an addressable URL is easier to be cached and correctly processed by the crawling party.

Two ways to arrange multilingual websites

The site supports multilingual site configuration and switching, and supports full-page HTML translation. In terms of implementation, there are usually two routes, and their relationship with the cache is different.

One is based on header negotiation, where the same address returns different language versions. Its advantages are short addresses and no need to expand the structure; however, the cost is the cache issues discussed in this article, as well as the ambiguity caused by the same address corresponding to multiple contents for the crawling party.

The other is to divide addresses by language, for example, using subdirectories or subdomains to separate different languages. Its address corresponds to the content one by one, and the cache almost never makes a mistake; however, the cost is that the site structure becomes larger, and the maintenance amount of the translation content increases accordingly.

The ability to generate translations for full pages by the system also introduces a third scenario: the translation may be at the same address as the original page or at a separate address, depending on the implementation. When deploying, it is important to confirm which route the translated product takes - if the translation is written as a static file and placed at the same address first, the priority of caching and the file layer will override the negotiation logic, making it easy to misjudge the direction during troubleshooting.

There is a significant difference between self-built websites and hosting environments on this point: when deploying on your own, you can control the negotiation rules and cache layer configuration at the same time; in the hosting scenario, it is often only possible to change the site side and cannot affect the cache key strategy of the middle layer, so it is more inclined to adopt the separate addressing scheme at this time.

Verification sequence

Do this in order and you can locate the problem within a few minutes.

First, directly connect to the source station and request the same address in two different languages separately, confirm that the responses are indeed different, and both responses carry statements of language influence. Then, repeat the same two requests through the cache layer to confirm that each one hits its own copy rather than the same one. Finally, check the unmodified response and the error response to ensure that their statements are consistent with the normal response.

If the second step appears with a string version, the handling methods are arranged in order of priority: supplement declaration, change the address to non-cachable, or migrate to a separate addressing scheme. The impact on hit rate increases in turn, but the certainty also increases in turn.

Common questions

What should be done if the hit rate decreases after adding the declaration?This is the inevitable cost of the correct behavior. You can place resources unrelated to language (styles, images) separately, so that they can continue to enjoy a high hit rate.

What language does the search engine capture?The request header of the crawling party usually tends to be the default language. If the site is aimed at a multi-language market, separate addressing is more controllable.

Can the language preference in Cookie replace the request header?But it can participate in the judgment, but it will make the cache problem more serious: the response differences brought by personalized credentials also need to be handled at the cache and declaration level.

Why does it sometimes work after a refresh?Intermittent performance may occur when the cache object expires or is replaced, which cannot be taken as evidence that the problem has been resolved, and should still be reviewed in order of verification.

Does the content generated by full-page translation need to be handled separately?It needs to be confirmed whether it is on the same address as the original page. If it is on the same address, it should take the negotiation declaration route; if it is on a separate address, it should verify the new address cache and site map coverage.

Related articles

After logging in, the page is stored in a shared cache, and how should the private and non-cacheable headers in the cache header be written.

The MDN's Cache-Control document states that 'no-store' indicates that no type of cache should store the response, 'private' means that it can only be stored in private caches, and it also hints that shared caches will reuse a response for multiple users, and personalized content should not be given to it. This article explains the boundaries of both and why member-tiered pages are more likely to have issues.

2026-10-11

Writing the type header of the upload directory correctly is not enough; why do we need to add a separate response header to prohibit content sniffing?

MDN document states that X-Content-Type-Options indicates that the type declared in Content-Type should be followed and not changed, nosniff will block the response when the type requested in scripts or styles does not match. This article explains where sniffing occurs, why the upload directory needs to be blocked again at the deployment layer, and what each layer manages within the site.

2026-10-11

To enable HTTP/3 on a web server, you need to adjust the port, certificate, and compilation options.

The Nginx official module document states that ngx_http_v3_module has provided experimental HTTP/3 support since version 1.25.0 and is not compiled by default. It requires --with-http_v3_module to enable, the example listening port is recommended to be consistent with HTTPS, and 0-RTT requires OpenSSL 3.5.1 or higher. This article explains the enablement sequence in four steps: compiling, listening, certificate, and library version.

2026-10-11

When the open source agreement is written as GPL, what should be noted when modifying and delivering to the customer.

Based on the official WordPress authorization page, the requirements of GPLv2 or later versions cover derived works, plugins and themes are considered derived works by the official, and there is a legal gray area. This article explains the three things to be delivered to the outside world, the boundary between multi-site and secondary development, as well as the authorization verification sequence at the selection stage.

2026-10-11

Why returning a 503 when the site is upgraded and maintenance page is displayed is more reliable than returning a blank page

The MDN 503 document states that this status code indicates that the server is not ready to handle the request, common reasons include maintenance or overload, the response should only be used for temporary conditions and should ideally include the Retry-After header with the expected recovery time; the document also hints that 503 indicates a temporary issue and should not be cached. This article explains how to configure the status code, retry time, and caching during the maintenance window.

2026-10-11

The page actually exists but always returns 404, what impact will it have on indexing?

The content is still in the library, but the front-end has deemed the page non-existent. The signal received by the search engine is that the resource has disappeared, and the inclusion and traffic will follow suit. This article explains why a unified error code is dangerous, the several cases of status codes being semantically分流, and the troubleshooting sequence of document status, pseudo-static rules, redirection, and site map configuration.

2026-10-11

The redirect address after successful login is brought by parameters, and if not verified, it may be used for what.

The login redirect parameter is an external controllable input. When no centralized verification is performed, a legitimate login process may be transformed into a bridge from a trusted domain to a phishing page. This article explains what such redirect addresses are used for, what types of values the whitelist should block, and the division of labor of captcha and frequency control on the login path.

2026-10-11

Vector icons can carry scripts, and when uploading images, it is necessary to filter out what content should be blocked.

Vector icons are not image data, but a document format that can include script elements. When uploading, it is necessary to filter out scripts and event attributes, external references, and large decompression volumes, while retaining normal display content. This article discusses the trade-offs between the cleaning list and black and white list strategies.

2026-10-11