简体   繁体   中英

asp.net mvc3 razor, javascript

I had created my webpage with asp.net mvc3 razor. When i had given release to the client with the modified .js files . The client cannot able to get the modified changes until he reloads or refresh the page. But i would like to find solution that there should be no requirement to client to refresh the page every time for the updated changes. But i would not like to change the settings in the google chrome( we are using google chrome for our web page).

I would like the change to be in the code only. Could any one suggest me the solution.

In your javascript files, put a querystring at the end of it. This will force the browser to reload the javascript files:

<script type="text/javascript" src="/path/to/script.js?version=2"></script>

Each time you redeploy js file changes, increment to version=3, version=4, and so on. Chrome (and any other browser) will think the file has changed, and reload it without using the previous version from cache.

You should check out Combres , it's available as a NuGet package. This will combine your javascript files, minify them and serve as a single file to the browser. That single file has a unique hash in the name which works around browser caching (the source of your problem).

All you have to do is install the package using NuGet and then list your JavaScript files in the combres.xml file in App_Data. It handles everything else for you.

As a bonus, it also works for CSS and combining and minifying your files will make your site much faster to load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM