Hi,
When we update the en.json file with new values and deploy it, some browsers continue to use a cached/previous version of en.json and do not retrieve the latest en.json file.
I've seen Angular avoid caching issues by adding a hash to the end of files generated by the Angular CLI at build time. Is this something that ngx-translate can already do?
Is there other ways to fix this problem?
Thanks,
Chris
Quick fix that will make ngx-translate load new json file every time you refresh page. Not efficient at all but simple and works;)
app.module.ts:
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json?v=' + Date.now());
}
@NgModule({
imports: [
...
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
Append your build version as a query parameter as @maciejcichowski way, so translation files will be requested in every new version.
I managed to fix this by adding a Cache-Control header with the value no-cache to the http response that contains the en.json response
Most helpful comment
Quick fix that will make ngx-translate load new json file every time you refresh page. Not efficient at all but simple and works;)
app.module.ts: