Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 500371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:04:49+00:00 2026-05-13T06:04:49+00:00

I use dynamic script loading to reduce the duration of the initial page load.

  • 0

I use dynamic script loading to reduce the duration of the initial page load. To ensure that the functions and objects defined by a script are accessible, I need to ensure that the script has been fully loaded.

I have developed my own Javascript library to this end, and thus did quite a lot of research on the subject, studying how it’s done in different libraries.
During a discussion related to this issue, Kyle Simpson, the author of LABjs, stated that:

LABjs (and many other loaders) set
both “onload” and “onreadystatechange”
on all script elements, knowing that
some browsers will fire one, and some
will fire the other…

You can find an example of this in the current version of jQuery as of this writing, v1.3.2:

// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
    if ( !done && (!this.readyState ||
    this.readyState == "loaded" || this.readyState == "complete") ) {
        done = true;
        success();
        complete();

        // Handle memory leak in IE
        script.onload = script.onreadystatechange = null;
        head.removeChild( script );
    }
};

That’s the state of the art, but during the analysis of a strange behavior in Opera 9.64, I came to the conclusion that, using this technique, the onload callback got fired too early.

I will post my own findings in answer to this question, and would like to gather further evidence and feedback from the community.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:04:50+00:00Added an answer on May 13, 2026 at 6:04 am

    In Opera, the script.readyState property cannot be trusted. For example, the readyState “loaded” may be fired before the script runs in Opera 9.64.

    I performed the same test in Opera 9.64 and Opera 10, with different results.

    In Opera 9.64, the onreadystatechange handler gets fired twice, once before and once after the script runs. The readyState property is “loaded” in both cases, which means that this value cannot be trusted to detect the end of the script loading:

    # Fri Dec 18 2009 17:54:43 GMT+0100
    # Opera/9.64 (Windows NT 5.1; U; en) Presto/2.1.1
    Test for script.readyState behavior started
    Added script with onreadystatechange handler
    readystatechange: loaded
    test1.js: Start
    test1.js: Start of closure
    test1.js: End of closure
    readystatechange: loaded
    

    In Opera 10, the onreadystatechange handler still gets fired twice with the value “loaded”, but both times after the script ran:

    # Fri Dec 18 2009 18:09:58 GMT+0100
    # Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10
    Test for script.readyState behavior started
    Added script with onreadystatechange handler
    test1.js: Start
    test1.js: Start of closure
    test1.js: End of closure
    readystatechange: loaded
    readystatechange: loaded
    

    These different behaviors indicate that onreadystatechange is not a reliable way to detect the end of a script loading in Opera. Since Opera also supports the onload listener, this other mechanism should be used instead.

    Based on the results of these tests, onreadystatechange should only be used to detect the end of script loading in Internet Explorer, and it should not be set in other browsers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 283k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Moron/Aryabhatta is correct, but a little more detail may be… May 13, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer You might look at java.util.PriorityQueue. If you're in a hurry,… May 13, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer It's not working since sayHello() doesn't return anything place return… May 13, 2026 at 4:23 pm

Related Questions

I have a JavaScript slideshow that pre-loads images out of a MySQL database and
I've been racking my head for two days trying to find a solution for
I'm looking for recommendations of a good, free tool for generating sample data for
This flickr blog post discusses the thought behind their latest improvements to the people
I'm using an external swf containing a number of font classes to load and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.