开发者

Prevent jquery from being referenced more than once?

开发者 https://www.devze.com 2023-04-01 05:41 出处:网络
Is there something I can wrap around the body of my jquery include file to prevent it from being included twice?My problem is that my application has multiple includes and I want to prevent jquery fro

Is there something I can wrap around the body of my jquery include file to prevent it from being included twice? My problem is that my application has multiple includes and I want to prevent jquery from being referenced in multiple includes and breaking.

My thoughts would be to open my jquery file (jquery-1.4.2.js) and put some sort of logic around the entire block of jquery library c开发者_开发百科ode.

Something like:

if (jQueryIsAlreadyIncluded()) { //jquery library code {(function(A,w){function ma(){if(!c.......

}


Try this

if(typeof jQuery == 'undefined'){
   //jquery library code {(function(A,w){function ma(){if(!c.......
}


Hmmmmm Boilerplate does this when using the googleapi jquery, so you could use it for local files too

    <script>window.jQuery || document.write('<script src="yourpathtojquery"><\/script>')</script>

This is only for jquery itself though, otherwise you could set some variables and then in each library check if the variable is set, if not include, else exclude.....

if(!($Mylib))
{
    //Your javascript here....

    Mylib = true;
}


perhaps

if (typeof jQuery === undefined) {

    // jQuery code

}
0

精彩评论

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