JavascriptTranslationMiddleware, added a solution to make caching stable #167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.