Skip to content

Conversation

LinusCenterstrom
Copy link
Collaborator

Currently we cache all files that go through the JavascriptTranslationMiddleware permanently since their filenames contain a content hash. This is incorrect if we change the translations without updating the source code. The new version of the JavascriptTranslationMiddleware uses an extra level of redirects to improve this (on by default, but configurable).

Instead of directly returning the translated file it instead returns a redirect to the same path but with a contenthash based on the translated filecontents in a queryparameter. This makes it safe to cache the result of the url with the queryparameter permanently. By default we also cache the redirect for 30 minutes (configurable) with a fairly high revalidate-while-stale header (also configurable). The first level of caching still makes it possible for clients to have stale translations for a bit but nowhere near as long as our current solution.

The reason for the extra redirect with the hashed filecontents on the url instead of just returning a fairly short max-age and a fairly long revalidate-while-stale header from the top-level is because revalidate-while-stale isn't supported in all browsers (Safari) and this would cause many unnecessary requests.

…e stable.

Currently we cache all files that go through the WebpackTranslationMiddleware permanently since their filenames contain a content hash.
This is incorrect if we change the translations without updating the source code.
The new version of the JavascriptTranslationMiddleware.cs uses an extra level of redirects to improve this (on by default, but configurable).

Instead of directly returning the translated file it instead returns a redirect to the same path but with a contenthash based on the translated filecontents in a queryparameter.
This makes it safe to cache the result of the url with the queryparameter permanently.
By default we also cache the redirect for 30 minutes (configurable) with a fairly high revalidate-while-stale header (also configurable).
The first level of caching still makes it possible for clients to have stale translations for a bit but nowhere near as long as our current solution.

The reason for the extra redirect with the hashed filecontents on the url instead of just returning a fairly short max-age and a fairly long revalidate-while-stale header from the top-level is because revalidate-while-stale isn't supported in all browsers (Safari) and this would cause many unnecessary requests.
@LinusCenterstrom LinusCenterstrom changed the title JavascriptTranslationMiddleware, added a solution to make caching safer JavascriptTranslationMiddleware, added a solution to make caching stable Jun 30, 2023
Copy link
Member

@itssimple itssimple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since files are now in conflict with master, things need to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants