-1

I am developing a website using angular and javascript, but each time I did some updates the client must clear the cache to feel this update. How can I force the browser to reload the updated files smoothly without asking the user to clear cache?

Noha Shehab
  • 393
  • 5
  • 12
  • 5
    set the proper headers on the server. Plenty of questions on the site about it and other tricks you can do. – epascarello Nov 06 '18 at 20:51
  • There are multiple way to achieve this. Specify what technology/framework are you using and do a search in Stackoverflow with your framework as one of the keywords – Alfredo A. Nov 06 '18 at 20:53
  • 1
    You can check [this](https://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers). Hope it helps! – Jorge Lopez Nov 06 '18 at 20:56

1 Answers1

3

There are a lot of different options here, but the idea is to append some kind of dynamic value to the end of the path when you include it.

For example:

<link href="styles.css?test=123" rel="stylesheet" />

That would force the browser to load the stylesheet from the server once, but then that version would be cached.

If you are using some kind of server-side language like PHP or .NET, you can put a dynamic value at the end that will be different every time the page loads for a user.

In PHP:

<link href="styles.css?test=<?=(new DateTime())->format("YmdHis")?>" rel="stylesheet" />
Mark
  • 418
  • 1
  • 4
  • 13