开发者

ASP.NET - Overriding Javascript and Styleheets cached by browser

I'm working on an asp.net website. I need to make sure my javascript and css updates will be immediately available for returning visitors, without them having to clear their cache to get the latest code. How can I force 开发者_StackOverflowthis when needed, and leave it alone on other occasions?

Thanks in advance.


Stackoverflow does this very elegantly IMO. You can see in there source there is a query-string variable passed.

<script type="text/javascript" src="http://sstatic.net/js/stub.js?v=778aaf5a38e2"></script>

This will force new load if that changes.


In order to reliably force a refresh of cached content on the browser you need to change the name / requested URL of the file somehow.

Often this is done by appending a query string to the URL (which is often ignored)

See When Does Browser Automatically Clear JavaScript Cache? for a more complete discussion.


You'll need to apply no-cache header to those resources, alternatively make the url dynamic somehow.

see - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜