In my previous article I have explained about how to get all files in a directory using C#.Net and Asp.Net. In this article I am going to explain about how to automatically update the version of css and js when file gets changed.
In order to do this, developers have to go to all the pages and then increase the version number. If you forget to do this on some page, that page may break because browser uses old cached script. To avoid this we should change the css and js version automatically whenever changes occur.
To achieve this include Update.cs in App_Code and Include the below code in Global.asax file.
The code will get the last modified date of the css and js file and add it as a version of the file. So every time you update the file automatically version will get updated. If you view the source of the page you can better understand it. Below is the screenshot of the output.
Do you like this article? Help us to improve. Please post your comments below.
Download Source Code: