2

I am doing a web project which has several javascript files, finding the front-end response a bit slowly especially on firefox. The factor related to server side has been ruled out, so I conclude that it must has something to do with my javascripts.
I currently use firebug to debug, using console.log(), or by commenting some codes here and there.
But it turns out to be very time-consuming! Does anyone has other efficient or better ways to help me? Thanks in advance.

********Below is part of the codes which take up most of the time, @Bill. Firebug reported an Undefined error to "mainTabs". But when I tried to redeclare mainTabs in load callback, it remained the same.******

var mainTabs = $("#main-tabs").tabs({
    selected: defaultTab,
    cache: true, //set tabs to cache the content
    load: function(event, ui){
            //want to preload the non-active tabs' content
            console.log("mainTbas: "+mainTabs.html());
            mainTabs.tabs("load", ui.index+1);
    }
});
1
  • 1
    How about providing some code examples/specifics? Commented Jul 19, 2012 at 4:52

1 Answer 1

2

Firebug has a script profiler you can use to find out where the problem might be. It's under the Console tab, right before the All button. Click the Profile button and then refresh your page (or do whatever is running slowly on your page). Click the Profile button again to get a table that will tell you what functions are taking the most time. Start there to try and optimize.

For you sample code, you need to declare mainTabs first. This should work (at least according to Preload JQuery UI tabs in the background which is what I assume you started with):

var mainTabs;  // declare mainTabs first.
mainTabs = $("#main-tabs").tabs({
                selected: defaultTab,
                cache: true, //set tabs to cache the content
                load: function(event, ui){
                    mainTabs.tabs("load", ui.index+1);
                }
            });
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, Bill. I tried, but all the functions called in the result table are from jquery.js. And the funcs are all anonymous. It does me a little help, coz I can't still decide where the problem lie.
Sort by inclusive time and find what code of yours is calling all of the jQuery. Something isn't right if that much time is being spent in jQuery. Do you have lots of animations or other things that use timers? It almost seems like you are creating timers in a loop or something.
I have updated the question, you can take a look at it again.thx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.