ASP.NET Core: asp-append Version Feature In ASP.NET Core
By FoxLearn 3/13/2021 11:38:52 AM 5.72K
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
- Unable to resolve service for type 'Microsoft.AspNetCore.Identity.RoleManager'
- HTTP Error 500.30 ASP.NET Core app failed to start
- How to Use IExceptionHandler in ASP.NET Core
- How to custom exception handling in ASP.NET Core
- How to create a custom AuthorizeAttribute in ASP.NET Core
- How to manually resolve a type using the ASP.NET Core MVC
- Differences Between AddTransient, AddScoped, and AddSingleton
- How to add security headers to your ASP.NET Core