ASP.NET Core: asp-append Version Feature In ASP.NET Core
By FoxLearn 3/13/2021 11:38:52 AM 5.49K
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
- ASP.NET Core: How to Create RDLC Report in ASP.NET Core
- How to fix Assets file 'project.assets.json' not found
- How to fix 'IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson'
- How to fix 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'
- How to set cookie ValidationInterval in ASP.NET Core
- How to fix LoginPath not working in ASP.NET Core
- How to fix Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager'
- How to Configure ASP.NET Core Identity password policy