0

I am new to using Jquery. One thing that surprises me is the size of the JQUERY File. I think the compressed version is around 100KB. This has a performnace problem on our Site. To overcome that, I would like to ask the community, Is there any way that the JQUERY File is loaded only once in a clients device. To explain more, Lets say when a user comes to Page A of our Site, We load the JQUERY File. Next time when the User navigates to Page B, How can we ensure that the same JQUERY File which was downloaded earlier for Page A is not downloaded again. Any help is appreciated

2 Answers2

1

If you were to include the jQuery js file from a CDN such as Google Hosted Libraries then the browser will cache the file after the first load. Additionally, as a lot of sites use the CDN the file may even already be in the cache.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Chris Pickford
  • 8,642
  • 5
  • 42
  • 73
  • Thaks. Do you know what is the URL for the latest File – user3170667 Feb 26 '15 at 15:06
  • Latest jQuery is as above. You can replace the version number in the URL with the one that you require. All Google hosted library URLs can be found here: https://developers.google.com/speed/libraries/devguide#jquery. – Chris Pickford Feb 26 '15 at 15:30
1

I havnt tried this, but a brief searching led me to this: https://stackoverflow.com/a/1828267/1304575

and also this: https://stackoverflow.com/a/15384309/1304575

(basically check if jquery obj exists or not, if not then add the script to the head inside a suitable 'script' element)

Although (as already pointed out) using CDNs will cache it.

(BTW the latest jquery core: 2.1.3 minified is 83KB which in my opinion is not that much considering the amount of functionality it provides)

hope it helps!

Community
  • 1
  • 1
suvartheec
  • 3,484
  • 1
  • 17
  • 21