Blog

How to reset CSS cache by forcing CSS files to refresh when using ASP.NET Themes?

When we load a web page to a browser it cache most of the resources on first load such as css files, images and javascripts files unless if it is not specify not to cache from the server (May be on user side). In most cases, when we load same web page again browser returns a cached copy.

In ASP.NET developements, when we work with themes, it will link all css files in the theme automatically to the page. Once we modify CSS files, it will be hard for us to clear uses browser cache to get fresh updates because CSS links will not be changed. One easy solution is for us to add a version number to CSS file links so user’s browser will reload css files from server.

You can use the following code block to add a version number to all theme CSS files. This way you can reset user’s CSS cache from browsers. You can add this to your Master Page so it will add a version number to all your CSS file links or you can add this to every page to go through the controls in your page header.

Another method would be to include a version number in to the theme name. For a example MyThemeV1 or similar. So each release would then be loading contents from a new URL hence the content should be loaded again for each user. Obviously this is more work than the 1st option but it should be one per release. Both of these options can be used without overheads to your application. It is up to you to choose the best according to your requirement.

 

Share this with

 

No comments have been posted yet. Please feel free to comment first!

 

Post a comment

Thank you! Your comment will be posted after it is approved.
Sorry! Something went wrong. Please try again.

 

 

 

Advertisement