Link to home
Start Free TrialLog in
Avatar of intoxicated_curveball
intoxicated_curveball

asked on

Best practice for jQuery ready scripts

This is a bit of a best practice question, I couldn't find the info on the web. My website is using several JavaScript functions (from the jQuery tools library). Of course they all require to be executed when the DOM is ready. My website is quite large - over 2000 content pages, and we are using a CMS. I'm wondering is it practical to have a globally loaded JavaScript ready document for all of these functions (even though they aren't being used on most pages)? Will it have any impact on the site speed, etc.?
Avatar of Roman Gherman
Roman Gherman
Flag of Moldova, Republic of image

Hi,

The js file loaded will be cached at first load and then just used from cache.
But then the performance depends on what is done inside that js file.

If you will perform some checks - if something does not exists -  a control for example then do not execute further then the impact will be very small.
Avatar of intoxicated_curveball
intoxicated_curveball

ASKER

I'm still wondering about the impact of it having to read the JavaScript and search the DOM for the respective elements everytime, even though the JS file may be loaded in cache, it's still using processing resources.

What be great if anyone has some reference documents to best practices for these type of scenarios?
Avatar of leakim971
ASKER CERTIFIED SOLUTION
Avatar of blueghozt
blueghozt
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry I don't think any of the answers are definite, please advise