Reputation: 6599
If jQuery is only needed on certain pages, will loading jQuery on these individual pages be helpful with overall website pages load time?
Given browser will cache javascript, it won't make much difference. But overall speaking, will it? Or at least it doesn't hurt to do that. Right?
Upvotes: 0
Views: 36
Reputation: 382150
You should never import a library that you don't use.
This being said
Upvotes: 2
Reputation: 103358
That's correct, loading the jQuery only on pages which require it will help performance for the pages that don't use jQuery. However, if a page containing the jQuery library has already been viewed, this won't make much of a difference as the javascript file will have already been cached locally.
Generally, unless you are only using jQuery on 1% if your pages, I don't think it hurts to put jQuery in the head
of every page.
If you are concerned about performance, you could link to the script hosted on Google. This has benefits because if another site the user has viewed has already downloaded this script, it will already be cached for your website.
https://developers.google.com/speed/libraries/devguide
Upvotes: 0