Solved

Best practice for jQuery ready scripts

Posted on 2011-03-24
5
163 Views
Last Modified: 2012-06-21
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.?
0
Comment
Question by:intoxicated_curveball
5 Comments
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35207494
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.
0
 

Author Comment

by:intoxicated_curveball
ID: 35209575
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?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35212076
0
 
LVL 6

Accepted Solution

by:
blueghozt earned 500 total points
ID: 35216613
best practice would suggest that you do not include all of the custom JS on all of the pages - your CMS should be able to allow you to specify which custom JS files to include in which page - if it doesn't allow you to specify this then perhaps you might want to think about introducing a system of your own  e.g. domain.com/about-us includes about-us.js as would domain.com/about-us/staff/john-smith i.e. about-us is the 'channel' and have a common-functions.js for your site-wide JS.

your libraries and plugins will be cached and not cause any client side processing issues - only the custom JS will do this so limit it to what is needed
0
 

Author Comment

by:intoxicated_curveball
ID: 35834525
sorry I don't think any of the answers are definite, please advise
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now