0

We have an app with combination: Angular5 + ASP.NET WebApi.

Supported browsers would be: Google Chrome, IE11+

After deployment to production with some changes to the client code the end users might still have old code cached somewhere. What is the solution to that ? Lets assume that client and backEnd releases are already versioned and we have access to that information.

One option would be to force the browser to clear its cache after the code detects that the version changed(Here the question would be as to how to do that). Another to maybe inform the user to clear the cache because the version changed (workaround).

What is the best way to tackle this problem ? I guess this is a pretty common scenario but I can't seem to find any good materials on the web on how to achieve this.

Regards

cah1r
  • 1,751
  • 6
  • 28
  • 47

2 Answers2

1

Build your application with the --prod flag, as intended by the CLI.

You also can run the ng build --help command (RTFM), which displays this flag :

--output-hashing=none|all|media|bundles 
(String) Define the output filename cache-busting hashing mode.
aliases: -oh <value>, --outputHashing <value>
  • It is already build with --prod flag. This issue seems to persist primarily in IE11 I guess. This is our build definition: node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --app=prod --env=prod --prod – cah1r May 18 '18 at 11:57
  • 1
    Then the issue is the browser, not the CLI. Advise your users to switch browsers, this will be waaaay easier than handling the cache busting yourself (and since the CLI already does that, chances are that even if you implement it for IE11, it won't work either) –  May 18 '18 at 12:07
  • 1
    This could be easier. Especially that IE11 and below versions are really horrible. Still this is one of the requirements and I have to look at different options on how to achieve this. I'll edit the topic to be more specific (that this is an IE issue) – cah1r May 18 '18 at 12:10
0

I would've expected that this issue would be inherently handled through the If-Modified-Since / Last-Modified Headers but several threads, such as yours seem to indicate that that is not the case.

There have been a few ways proposed to get around that. The most commonly used is to reidentify the file through an additional version indicator in the url, see this for further information.

Also MVC 6 is able to help you with that.

You may need to adapt this approach to work with your choice of framework combination. For example a little Helper that serves your angular files from a version specific subfolder.

Severin Jaeschke
  • 661
  • 7
  • 22