?
Solved

Best practice for jQuery ready scripts

Posted on 2011-03-24
5
Medium Priority
?
169 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 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

752 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