开发者

will Including jquery more than once to a page create any issue ? why?

Let assume we have a layout , controller and view.

We are including jquery in layout, controller and view even if it is not needed.

Jquery is not working after that !! what will be wrong ?

What should be the best practise? Include it in layout and it will be automatically included all p开发者_如何学Goages wuth that lay out.

Please suggest


why not do a conditional include in all 3 places. So whatever loads jQuery first its OK as the other 2 would not include it again on your web page.

You can test if the jQuery object is defined or not. And include the script tag only if the jQuery object is not defined.

if(typeof(jQuery) == undefined){
    var jqS = document.createElement('script');
    jqS.src = 'jquery.min.js';
    jqS.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(jqS);
}


someone wrote a script adressing this issue: http://www.purpleivy.net/web-design/development-tips/2010/03/including-jquery-multiple-times/

it allows you to include jquery multiple times without disrupting its functionality

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜