Reputation: 7236
Can I use JavaScript to check whether JQuery is (already) downloaded (cached) on the target web browser (user) or not? For Example:
If (JQuery-from-Microsoft-CDN-downloaded)
Then use http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js
Else if (JQuery-from-Google-APIs- downloaded)
Then use http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
Else if (JQuery-from-code.jquery.com- downloaded)
Then use http://code.jquery.com/jquery-1.4.4.min.js
Else use jQuery from my own website.
Means that using the ability of javascript to check whether one of them is downloaded on the target User (Web Browser), if not then use jQuery from my own website otherwise if true then use that version of JQuery that is downloaded on the target User.
Upvotes: 5
Views: 673
Reputation: 6088
There are few ways to check if jQuery is loaded
var isLoaded = (jQuery) ? true : false;
or
var isLoaded = (typeof jQuery == 'undefined') ? false : true;
If your script is loaded inside same document that jQuery included you can parse DOM and check if any of the SCRIPT tag containing link to any of the CDN's
var jQueryVersion = isLoaded ? jQuery.fn.jquery : false;
Upvotes: 0
Reputation: 630489
You can't do this, another case where the same-origin policy prevents any mechanism to accomplish this. If you think about it, it makes sense...any mechanism you could use to accomplish this, you could also use to figure out which sites someone visited, by seeing which files they have cached.
Upvotes: 4