?
Solved

How can i defer loading of certain javascript files until everything else has loaded?

Posted on 2010-09-05
3
Medium Priority
?
315 Views
Last Modified: 2013-11-19
Hi, i'm writing a text editor with a bunch of features, the problem is that the page (and hence my editor toolbar) takes some time to load due to all the javascript files it's pulling in. What i realized however is that not all files should be necessarily loaded up straight away. For example the code for the right-click context menu could be deferred, and even the spell checker (which is very large!) need not really be loaded straight away (but moments later). I'd be happy for these features be loaded AFTER everything else. So ideally wouldn't even start to load until everything else INCLUDING other javascripts resources are loaded (not just the html). In jquery i use:

$(document).ready()

.. to execute my code which initializes the toolbar functionality. Note the toolbar is actually constructed via javascript, i.e. it takes the html code and converts it into some windows tab style. As a result the toolbar can't be rendered until document.ready() gets executed (i hide the toolbar until this code is executed). Therefore that code is competing i guess with all the other javascript resources being downloaded on the page! If it was a plain html/css toolbar then obviously the toolbar would look fine immediately, if you're with me. So i ideally the javascript which constructs the toolbar should be run AFTER the html has been loaded but before certain javascript resource.

Any ideas as to how to resolve the dilema as described in this post's title? (Many thanks)
0
Comment
Question by:paddycobbett
[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
3 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 600 total points
ID: 33607440
you can load those javascript files using jquery'
http://api.jquery.com/jQuery.getScript/
0
 
LVL 4

Accepted Solution

by:
MichaelMH earned 1400 total points
ID: 33635525
You can do it also using plain JavaScript. You just have to ensure that all the resources in which you are interested are loaded first. The you can dynamically create/insert SCRIPT tags in the body and start loading the scripts you need.
0
 
LVL 1

Author Closing Comment

by:paddycobbett
ID: 33794358
thanks  =)
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

771 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