views:

407

answers:

2

Hi All,

I have a page which loads divs of rounded corners. And on each div (including all the inner divs, spans inside this div) I call many events related to them. Now the problem I'm facing is load time. Do we have any approach to load the script for rounded corners first in "ready" function and rest of the events dynamically when I mouse over on the main div? Any approach which reduces my loading time would be of great help!

Example:

$(function(){
    $('.inner').corner({
     tl: { radius: 6 },
     tr: { radius: 6 },
     bl: { radius: 6 },
     br: { radius: 6 }
    });

    // loadDivEvents() in this we call the rest of the events upon
    // mouseover or any other event without multiple calls

});

function loadDivEvents(){
    //this may have many events/ajax calls
}
A: 

What is the actual issue with load time, if I may ask?

When the page is first loaded, any event-related functions are (usually) just getting tied to the elements in the page so that if and when the event occurs, the event-related function will execute. So I don't know if this will really impact your page load time.

What can impact your page load time is having tons and tons of event-related functions that you are trying to associate one at a time on page load.

For instance, if I have 10 lists, and each list has 10 list items, and I want any of the list items to turn green on hover-- if I have javascript that defines each of these 100 events separately, that may tax my overhead.

But!

If I move the binding of these events to AFTER the page loads and have this happen when I first mouse over the main div (or window, or on any event that will almost always occur next), then the overhead just gets passed to THAT event. The page is loaded, but now it's frozen while the events get dealt with. My user is really irked because he can't scroll down, and if the problem is bad enough, he can't close the page or switch to another window. He expected this when the page was taking forever to load, now it's just this random freeze that always happens when he goes to your page.

So if there is a page load issue, a better solution may be to find out if there is redundancies or unnecessary functions running. In the above example I gave, I could simply say "when ANY list items are moused over, they turn purple" that's one binding, versus 100. Or I may have made the easy mistake of having each of those 100 bindings actually do something (like check the value of the list item) which it really only needs to do AFTER the event that triggers it, not during page load. That would be 100 stalls that I didn't even mean to happen once during page load.

Anthony
Yeah you are right... as you said the page load depends mainly on the "redundancies or unnecessary functions running". i tried to optimize the code. The major load time is because of the rounded corners script i am using. But i just wanted to know whether there is a way to do something like this(have few events in ready function and fire rest of the events when i hover on a particular div). Anyways thanks for your answer.
kayteen
I'm not sure if it would help at all, but have you tried modularizing the two parts of the script? curvy corners in one js file and events in another? See if you have any luck maybe putting one before the other? What rounded corners script are you using? I've had nothing but sour luck with corners for over a year now. Have you tried doing the rounder corners with CSS (-moz-border-radius) just to confirm that the page loads nicely and looks right when you remove the rounded corners script?
Anthony
i tried modularizing... but its still the same.Coming to "rounder corners with CSS (-moz-border-radius)" this works only in Mozilla... but is there a way to make it work in IE??Right now i'm using this, http://blue-anvil.com/archives/anti-aliased-rounded-corners-with-jqueryThis script takes lot of time for me.
kayteen
I'm having around 250 outer divs(250 inner divs) on a page. Both the inner and outer divs need to have rounded corners. The divs get loaded normally without rounded corners script. But i use corner script it takes lot of time and hangs. This is the major issue for me. :(
kayteen
I was curious about the -moz-border-radius in terms of load time. If you use the pure CSS method (and thus cut out that script) do you get the desired results in FF? (Basically I'm wanting to confirm that by using the CSS method you get a glimpse of the perfect world, and thus we can definitely start thinking about other curvy-corner solutions).
Anthony
Yes i am able to get what i need in FF but not in IE. :(Anyways i fixed this thing by going with images instead of divs. Will let you know if i find some optimized solution for rounded corner divs
kayteen
A: 

I fixed this thing by going with images instead of divs. I found it to be the best way to resolve this.

kayteen