Let's say we have several different sites: website1.com, website2.com, website3.com. We use jQuery for all of them and include it from the CDN, for example googleapis.com. The expected behavior of the browser would be to cache it once and use it for all other websites. Chrome seems to do this, but Safari loads jQuery for each domain.
Example
- With the given JS code below nytimes.com , bbc.com and dw.de in Chrome.
- Add jQuery to your first website and see the Network tab of your DevTools. He will say that he got jQuery.
- Now open any other site and add jQuery again - the answer will be "from the cache."
However, Safari will say jQuery loading for each domain, but try to open any web page in one of the domains and add the script again - you will see that now it says that it got jQuery from the cache. Thus, it looks like it is caching data for the domain, even if it already downloaded the resource from the exact URL for another domain.
Is this assumption correct, and if so, how to fix it?
Code you can copy / paste:
setTimeout(function() { var SCRIPT_SRC = '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'; var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = SCRIPT_SRC; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); }, 0);
UPD: Tested with a static image.
test.com, test2.com and test3.com have <img src="http://image.com/image.jpg" /> . In all browsers except the Safari access log, only one is displayed - the first request for an image. Safari receives an image for each new domain (but not a subdomain).
safari caching browser-cache cdn google-cdn
Daniel JF
source share