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 3722308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:51:26+00:00 2026-05-19T05:51:26+00:00

This question relates to a previous question here: Reducing number of calls to the

  • 0

This question relates to a previous question here:

Reducing number of calls to the methods of a JavaScript object

When profiling these two code snippets with Firebug:

function ie6PNGFixLoader(scriptURL) {
    if(arguments.length > 0) {
        for (var i = 0; i < arguments.length; i++) {
            $.ajax({// load PNG fix scripts
                url: arguments[i],
                cache: true,
                dataType: 'script'
            });
        }
    } else {
        return false;
    }               
}

var pngFix = "/Global/ICIS/Scripts/DD_belatedPNG_0.0.8a-min.js";    
var pngList = "/Global/ICIS/Scripts/DD_PNG_listing.js"; 
ie6PNGFixLoader(pngFix, pngList);

and

function InjectScriptsAndExecute(url) {
    this.url = url;
}

InjectScriptsAndExecute.prototype.InjectMethod = function() {
    var inject = $.ajax({
                        url: this.url,
                        cache: true,
                        dataType: 'script',
                        async: false, // Otherwise you cannot depend on the parse order
                        }); 
    return inject;  
}
var pngFix = new InjectScriptsAndExecute("/Global/ICIS/Scripts/DD_belatedPNG_0.0.8a-min.js");
var pngList = new InjectScriptsAndExecute("/Global/ICIS/Scripts/DD_PNG_listing.js");
pngFix.InjectMethod();
pngList.InjectMethod();

It appers that the latter’s calls to the InjectScriptsAndExecute method are much faster than the former’s calls to its function. A colleague has asked me why when i mentioned the performance improvement but i cannot explain it myself.

Any advice for better understanding would be greatfully received.

  • 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-19T05:51:27+00:00Added an answer on May 19, 2026 at 5:51 am

    Arguments is not Array it’s an Object that somewhat behaves like an array.

    if(arguments.length > 0) { // Slow AND superfluous
        for (var i = 0; i < arguments.length; i++) { // Even SLOWER
            arguments[i]; // Holy...
    

    Cache the length, accessing the property is slow, IE6 won’t have no optimization at all for .length and I even suspect it to be really slow when using the arguments[i] since it is not a real Array and might therefore do an unoptimized property lookup.

    If you want to get the best of both worlds, pass a normal Array, use a plain for loop, and cache the length.

    function ie6PNGFixLoader(scripts) {
        for (var i = 0, l = scripts.length; i < l; i++) {
            $.ajax({// load PNG fix scripts
                url: scripts[i],
                cache: true,
                dataType: 'script'
            });
        }              
    }
    
    ie6PNGFixLoader(["/Global/ICIS/Scripts/DD_belatedPNG_0.0.8a-min.js",
                     "/Global/ICIS/Scripts/DD_PNG_listing.js"]);
    

    EDIT

    To make it clear, timing the loop is useless, the request is async, all you do is timing a loop and a call to $.ajax there’s no point in optimizing here, especially not for two entries. Even in IE6, doing the Ajax call itself (even just calling $.ajax) will be way slower then the loop.

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

Sidebar

Related Questions

This relates to my previous question (which can be viewed here ). I'd like
This code is taken from a previous question, but my question directly relates to
This is related to my previous question here . I want 4 divs (absolute
This is a related to a previous question I have asked here, see the
This question is related to a previous question of mine That's my current code
This question is in continuation to my previous post located here . Since there
This is related to my previous question about selecting visible elements . Now, here's
This question relates to Francois Deschenes's answer to one of my previous questions. I
This question is related to a previous post of mine Here . Basically, I
This question is related to my previous post Image Processing Algorithm in Matlab in

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.