Solved

Best practice for jQuery ready scripts

Posted on 2011-03-24
5
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View > Style menu 3 32
Add Rows on a Table 8 50
Textbox autocomplete using jquery in asp.net 13 46
How does this modal gets closed? 6 41
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

739 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