开发者

jQuery When using an iframe, should I try to consolidate inner and outer instances of jQuery?

开发者 https://www.devze.com 2023-01-22 17:23 出处:网络
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.

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 currentl开发者_开发知识库y, 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消