How to expire cached resources on your browser from your web application?

| | 1 min read

Often, when you update styles or images on your website, the users of your web application might still get the old logo or style. This is because the browser caches the resources on your web application. Hence, when then user tries to access the application, it will be loaded from the local computer, not from the server.

To workaround this, you can append a random number as a query string to the resource when you want users to force download the resource from the server. It would be good if you can use the hash value (md5 or sha2 or any hash) of the content of that file, so that the browser will invalidate its cache only if the content of the resource change.

Eg. if it is a css,

<a href="http://www.myweb.com/css/style.css?d41d8cd98f00b204e9800998ecf8427e" >Reference</a>