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

Browser Caching is stopping us get the latest version of en.json #1005

Closed
chris31389 opened this issue Feb 7, 2019 · 4 comments
Closed

Browser Caching is stopping us get the latest version of en.json #1005

chris31389 opened this issue Feb 7, 2019 · 4 comments

Comments

@chris31389
Copy link

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

@maciejcichowski
Copy link

maciejcichowski commented Mar 8, 2019

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

@Abdulrahmanh995
Copy link

Append your build version as a query parameter as @maciejcichowski way, so translation files will be requested in every new version.

@chris31389
Copy link
Author

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

@michcio1234
Copy link

For future generations:
if you have this in your nginx config (e.g. because you serve an Angular webapp with it):

        location / {
            try_files $uri$args $uri$args/ /index.html;
        }

then you must add another location block similar to this (notice no $args):

        location /assets {
            try_files $uri $uri/;
        }

Otherwise the browser will try to download a file with ?v=... in its name, which clearly doesn't exist.

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

No branches or pull requests

4 participants