Solved

Best practice for jQuery ready scripts

Posted on 2011-03-24
5
164 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

20 Experts available now in Live!

Get 1:1 Help Now