馃殌 Feature Proposal
I've been struggling for a few months to find the right approach to caching using i18next in combination with react.
Using a Create React App template, most examples I've found suggest to place resource files in public/locales/en/translations.json and to then use a plugin like i18next-http-backend to load them.
However, this seems to have the flaw that if a new version of the project is published with modified translations these won't be picked up, unless you configure your server in such a way to add no-cache, no-store headers to all resources files in this path.
This does mean that:
- These resource files will never be cached, which is a step too far.
- You need to configure your server to add these headers.
Looking at the output of a Create React App build, you'll normally have a bunch of generated .js files with hashes assigned to them. Wouldn't it make a lot more sense if there was a way to also add hashes to these translations?
I know that an alternative is to use cache-busting like this:
backend: {
loadPath: "/locales/{{lng}}/{{ns}}.json?version={{currentVersion}}",
},
But then you'd need to add some infrastructure to provide that currentVersion, which feels like setting up a work-around for a very common case.
Motivation
I think i18next configuration should be kept in one place and not require configuration on the server end or exposing version numbers in the building step.
Example
I'd hope that aside from maybe turning on a configuration flag, the usage of i18next or react-i18next would remain the same.
Only the build output would change and the calls to fetch the resouces.
Note
I'm open to other suggestions for handling caching, as I might be missing something obvious.
馃殌 Feature Proposal
I've been struggling for a few months to find the right approach to caching using i18next in combination with react.
Using a Create React App template, most examples I've found suggest to place resource files in
public/locales/en/translations.jsonand to then use a plugin like i18next-http-backend to load them.However, this seems to have the flaw that if a new version of the project is published with modified translations these won't be picked up, unless you configure your server in such a way to add
no-cache, no-storeheaders to all resources files in this path.This does mean that:
Looking at the output of a Create React App build, you'll normally have a bunch of generated
.jsfiles with hashes assigned to them. Wouldn't it make a lot more sense if there was a way to also add hashes to these translations?I know that an alternative is to use cache-busting like this:
But then you'd need to add some infrastructure to provide that
currentVersion, which feels like setting up a work-around for a very common case.Motivation
I think i18next configuration should be kept in one place and not require configuration on the server end or exposing version numbers in the building step.
Example
I'd hope that aside from maybe turning on a configuration flag, the usage of i18next or react-i18next would remain the same.
Only the build output would change and the calls to fetch the resouces.
Note
I'm open to other suggestions for handling caching, as I might be missing something obvious.