How to force browsers to get latest script files on ASP.NET pages in automated way

I was looking for a nice way how to force browsers to refresh its cached version of files and reload script files after the change occured.

Usually we link JS files or CSS files like this:

If you want to force refresh, you can amend parameters to url, ie.

Well, this is manual way, so how do it in automated way, so I do not have to care about it? There is several ways how to do it, I will just mention one, which is simple and reliable and you do not have to remember to increase anything upon deployment. (it’s not my idea, thanks to Adam Tegen and his answer in stackoverflow). I took the liberty to change it so it’s possible to use in ASP.NET webforms as well.

 

In ASP.NET page link the file as:

 

Leave a Reply

Your email address will not be published. Required fields are marked *