admin管理员组文章数量:1425820
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
3 Answers
Reset to default 4Setting 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.
本文标签:
版权声明:本文标题:javascript - Elegant way to force client browsers to re-download our asp.net web app's .css and .js files (without total 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745399383a2656964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论