Solved

Best practice for jQuery ready scripts

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert on input text 2 23
Popup write two lines 3 22
Hide and Unhide Table 6 24
sort Multi-dimensional array 6 8
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
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 style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

740 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