tags:

views:

366

answers:

1

I am using YUI 2.7.0 and the YUI Loader in several places in one page, and FireBug shows me that, for instance, yahoo-dom-event.js is being loaded several times (by pretty much all of the loader instances).

If my page has two "modules", and each one creates a YUI container, and uses the YUI loader to do so, then FireBug shows me that "container-min.js" is being requested twice.

Is this correct? Or am I doing something wrong?

A: 

Can you post some sample code? It should not be doing that. It should be detecting what you already have. You're not using the sandbox method, are you?

Also, you didn't ask this, but I'm curious why you are using the YUI loader in several places? Why not load the bare minimum of what you need then lazy load the less using the onSuccess method? Or is that what you mean by several places (the onSuccess calls another)?

Keith Bentrup
I'll try and come up with a code sample but in the meantime I have changed it to just use one YUILoader object, which is instantiated at the top of the page, and then various components of the page tell it which modules they need loaded. At the bottom of the page I call the loader object's insert() method.However, why does the YUILoader only let you have one "onSuccess" function? What if I've got an autocomplete and a container, and they both need some stuff to happen onSuccess? Why can you specify multiple onDOMReady() events, but only one YUILoader.onSuccess() event?
Sean
You can stuff as much code as you want in the onSuccess. It will fire once when all the required modules are ready. However, you can use the one onSuccess to trigger another instance of yuiloader (with it's own onSuccess function). I have found a couple instances where that is useful.
Keith Bentrup
What I wound up doing is creating an array of functions pointers. Each module on my page that needs something to be done in the loader's onSuccess() method adds a function to that array. Then the onSuccess() method just loops through that array, executing each function in it.Kind of strange that I need to do that. I really wish the loader's onSuccess() event could trigger multiple callbacks, kind of like the onDOMReady() event.
Sean
Just to clarify what you're doing .... so you're using the array of function pointers rather than named functions wrapped in an anonymous function? B/C you don't know which functions you are going to call until runtime and you need a data structure to hold them in your callback? Sounds reasonable.
Keith Bentrup