Search code examples
javascripthtmlcdn

Is/can a resource (js-file) from a CDN be shared across websites/browser tabs?


I'm not finding a definite answer on the web.

Lets say we have two sites both pull jquery from the same CDN.

  • pageOne.com > mycdn.com/jquery

  • pageTwo.org > mycdn.com/jquery

Now

  1. I go to pageOne.com.
  2. jquery is downloaded from mycdn.com/jquery.
  3. I go to pageTwo.org (on second tab)

Question: Is jquery downloaded again for pageTwo.org (its the same CDN and the same jquery js file), or can I use the browser cache for pageTwo.org? (i have already downloaded it when I was on pageOne.com before)


Solution

  • The single cached version is used for both sites. The URL for the jQuery library stays the same. It doesn't matter what references it.

    This is one of the main benefits of using a common CDN for common libraries... the fact that the user will probably have cached it already from some other site.