Core: Browser Caching is stopping us get the latest version of en.json

Created on 7 Feb 2019  路  3Comments  路  Source: ngx-translate/core

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

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:

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]
      }
    }),

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Snap252 picture Snap252  路  3Comments

madoublet picture madoublet  路  3Comments

rbaumi picture rbaumi  路  4Comments

guysan picture guysan  路  4Comments

IterationCorp picture IterationCorp  路  3Comments