Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavascriptTranslationMiddleware, added a solution to make caching stable #167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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