Is it the filename or the whole URL used as a key in browser caches?

前端 未结 10 1177
旧巷少年郎
旧巷少年郎 2020-12-15 04:24

It\'s common to want browsers to cache resources - JavaScript, CSS, images, etc. until there is a new version available, and then ensure that the browser fetches and caches

10条回答
  •  旧巷少年郎
    2020-12-15 05:18

    Yes, any change in any part of the URL (excluding HTTP and HTTPS protocols changes) is interpreted as a different resource by the browser (and any intermediary proxies), and will thus result in a separate entity in the browser-cache.

    Update:

    The claim in this ThinkVitamin article that Opera and Safari/Webkit browsers don't cache URLs with ?query=strings is false.

    Adding a version number parameter to a URL is a perfectly acceptable way to do cache-busting.

    What may have confused the author of the ThinkVitamin article is the fact that hitting Enter in the address/location bar in Safari and Opera results in different behavior for URLs with query string in them.

    However, (and this is the important part!) Opera and Safari behave just like IE and Firefox when it comes to caching embedded/linked images and stylesheets and scripts in web pages - regardless of whether they have "?" characters in their URLs. (This can be verified with a simple test on a normal Apache server.)

    (I would have commented on the currently accepted answer if I had the reputation to do it. :-)

提交回复
热议问题