What is asp-append-version attribute in Asp.net core?

Dung Do Tien Aug 13 2020 1015

I am studying Asp.net core 3.1, and now I want to import a js external file to an Html page, inside of <script> tag   I have an asp-append-version="true" attribute, I think this is an attribute of Asp.net core, I don't know why we should use it?

<script src="~/js/site.js" asp-append-version="true"></script>

Thank you for any explanation!!!! 

Have 1 answer(s) found.
  • S

    Sandeep Kumar Aug 14 2020

    Oh, this is a new function very helpful in Asp.net core. If you add asp-append-version="true" attribute to <script> or <style> tag Asp.net core will auto add version to end of URL path. This version always unique and change after each deploying a new code version.

    It always creates a new URL to help browser auto clear cache for this file and always update the latest code

    Your code :

     <script src="~/js/site.js" asp-append-version="true"></script> 

    Code after compile and display response to the client:

     <script src="/js/site.js?v=Ynfdc1vuMNOWZfqTj4N3SPcebazoGXiIPgtfE-b2TO4"></script> 
    
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close