views:

21

answers:

1

I code the game over at ninjawars.net, and have recently consolidated most of my (ugly) javascript code into a single object that gets re-used for the inner frame and the outer frame.

We were going to consolidate the same instance of jQuery as well (i.e. making it a Global so that it is accessible via $ everywhere, but is only 1 jQuery object, as opposed to what I believe is happening currently, which is that just including the jQuery library in the outer frame creates an instance of jQuery, and including in the inner iframe creates another.

Is it advisable to try to reuse a single instance (when a page is actually being loaded inside the iframe) of jQuery, and if so, how should I go about it?

+2  A: 

If your inner <iframe> is going to reload as a new page (and, if it's not, one might wonder what the point of the <iframe> is), then I'd say that trying to "consolidate" the jQuery objects is not a good idea if you're trying to support older IE versions (at least up to 7, and maybe 8). IE is really picky about object lifecycles, and Javascript objects instantiated in one window but referenced in another can make those browsers really nervous.

It's not really that wasteful or bad to have two instances of jQuery. Let the performance problems - if any - come to you and manifest themselves before trying to do something difficult about it.

Pointy