ASP.NET Core: asp-append Version Feature In ASP.NET Core
By FoxLearn 3/13/2021 11:38:52 AM 6.05K
We often use css, js files for our website, the problem every time you update the css, js file, the user side doesn't automatically download the new version.
To solve the problem of downloading new version css and js files, we usually clear the cache or press the refresh button. This is annoying for the user.
The good news is that ASP.NET Core has a solution to this problem. You can use asp-append-version="true"
To turn this feature ON, we just need to add the above special attribute to the HTML tag of the JS, CSS or Image file as shown below.
CSS
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
JS
<script src="~/js/site.js" asp-append-version="true"></script>
When you run the web page, open the html source, you can see the following. Just right click on your web, then select Inspect or you can press Ctrl + U.
CSS
<link rel="stylesheet" href="/css/site.css?v=S2ihmzMFFc3FWmBWsR-NiddZWa8kbyaQYBx2FDkIoHs">
JS
<script src="/js/site.js?v=4q1jwFhaPaZgr8WAUSrux6hAuh0XDg9kPS3xIVq36I0"></script>
Now every time you update the css or js file, the browser will automatically download the new version of the css or js file to the user's computer. So it means there's no need to use Ctrl + F5 or Ctrl + R to refresh the web page
- Options Pattern In ASP.NET Core
- Implementing Rate Limiting in .NET
- IExceptionFilter in .NET Core
- Repository Pattern in .NET Core
- CRUD with Dapper in ASP.NET Core
- How to Implement Mediator Pattern in .NET
- How to use AutoMapper in ASP.NET Core
- How to fix 'asp-controller and asp-action attributes not working in areas'