Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

how to force the user to load the JS file and CSS file when the related file changed. #7305


User avatar
0
banksearch created

we use the ASP Zero to devlop our web applications(ASP core MVC + Jquery).

in the website project, there are many js file and css files in the MVC website project, like folder below: ..\wwwroot\view-resources\Areas\App\Views\Tenants

when we edit the js and css files and deploy to Azure, we need to ask the user to clear their caches from browser and reload the website to get the changes of JS or CSS file.

is there a way to force the client user to load the changed js or css file automatically?

we checked from stackoverflow, and there are many different way to force user udpate the js file, like add version number to the end of js path: <link rel="stylesheet" href="foo.css?v=1.1"> but there are many js and css files in the project, we do not want to update all the js file once the version change, just want to update the js file changed.

we don't want the js files to download EVERY time a user visits the page, only when one JS file is changed, and then, only the changed file is downloaded.

another way I found:

In ASP.NET Core (MVC 6) this works out of the box via the asp-append-version tag helper: <script src="scripts/myjavascript.js" asp-append-version="true"></script> <link href="styles/mystyle.css rel="stylesheet" asp-append-version="true" /> https://stackoverflow.com/questions/2185872/force-browsers-to-get-latest-js-and-css-files-in-asp-net-application https://stackoverflow.com/questions/33342643/how-does-javascript-version-asp-append-version-work-in-asp-net-core-mvc can we use this way in our ASPZERO web app?

is there a better solution?

Many thanks.


No answer yet!