ASP.NET Core: asp-append Version Feature In ASP.NET Core
By FoxLearn 3/13/2021 11:38:52 AM 6.13K
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
- Boost Your ASP.NET Core Website Performance with .NET Profiler
- The name 'Session' does not exist in the current context
- Implementing Two-Factor Authentication with Google Authenticator in ASP.NET Core
- How to securely reverse-proxy ASP.NET Core
- How to Retrieve Client IP in ASP.NET Core Behind a Reverse Proxy
- Only one parameter per action may be bound from body in ASP.NET Core
- The request matched multiple endpoints in ASP.NET Core
- How to Create a custom model validation attribute in ASP.NET Core