javascript - Elegant way to force client browsers to re-download our asp.net web app's .css and .js files (without total

Our asp web application allows our (large) .css and .js files to be cached by client browsers for faste

Our asp web application allows our (large) .css and .js files to be cached by client browsers for faster performance.

But whenever we deploy a new version, we get phone calls from users about how the page looks messy and is full of javascript errors. It turns out, their browser didn't re-download the changed .css and .js files. Ctrl-F5 always fixes it.

Is there any way to force a re-download after upgrade deployments, without setting it not to cache (and thus slowing our application down)?

I've found this (manually changing reference to every file every deployment): How do I force a given file to expire in the cache?

and this (same thing but checksum calculation on every page load): Needed advice on how to implement js/css versioning

But surely there are more reasonable solutions than that...?

Our asp web application allows our (large) .css and .js files to be cached by client browsers for faster performance.

But whenever we deploy a new version, we get phone calls from users about how the page looks messy and is full of javascript errors. It turns out, their browser didn't re-download the changed .css and .js files. Ctrl-F5 always fixes it.

Is there any way to force a re-download after upgrade deployments, without setting it not to cache (and thus slowing our application down)?

I've found this (manually changing reference to every file every deployment): How do I force a given file to expire in the cache?

and this (same thing but checksum calculation on every page load): Needed advice on how to implement js/css versioning

But surely there are more reasonable solutions than that...?

Share Improve this question edited May 23, 2017 at 11:49 CommunityBot 11 silver badge asked Jul 13, 2013 at 3:56 MGOwenMGOwen 7,34713 gold badges60 silver badges72 bronze badges 1
  • What is the solution that you reached? Can you please post? – LCJ Commented Nov 6, 2013 at 13:14
Add a ment  | 

3 Answers 3

Reset to default 4

Setting the version number in the file works well for us:

<script type="text/javascript" src="somefile.js?v=1.0"></script>

As long as you change that version number each "release", the browser thinks its a new file.

You could do this by simply having a version number in a global file (like a config file or something) and then setting the variable on each script/css tag you wish.

You can now append asp-append-version="true" to a <script> or <link> tag to solve your problem automatically.

<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />

<script src="~/js/index.js" type="text/javascript" asp-append-version="true"></script>

Short article explaining usage

Microsoft Reference


The best approach is to use the versioning in file name. If you are using code versioning like SVN, Microsoft Team Foundation etc, then you can use the last checkin number as suffix to file name, for example, let say the current checkin number is 1321 (or you can also use time stamp yyyy-mm-dd-hh-mm ie 2015-01-15-17-15)

therefore somefile.js will bee somefile_v1321.js or somefile.js will bee somefile_v2015-01-15-17-15.js

Now you will wonder there is so much file name change happening here. The answer is, if your releases are very frequent, then consider using scripting language like Ant scripts, which can change the JS and CSS import file names in release files.

Every time new deployment will take place, the resources will have a new unified path, which will be unique to the browser, so it will do fresh load.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399384a4626028.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信