Reputation: 11980
I am creating a piece of JavaScript to be deployed to sites that are, at the moment, unknown to me.
This piece of code is supposed to do something that would be so much easier if I could just do it with jQuery, but I can't include any external libraries in this code because:
Now my question is: Is there a tool that would help me extract just the specific code-paths my code uses from the external library (jQuery) so that I could embed them directly into my code as part of it (using namespaces, etc.)?
Or it could be that my question is even wrong to begin with.
Upvotes: 2
Views: 187
Reputation: 35679
I know it conflicts with the first caveat but you could include jquery dynamically in your code by writing out the script element to a CDN e.g.
http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js
var headID = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js';
script.onload = function() { initialiseJQuerySpecificCode(); };
headID.appendChild(script);
function initialiseJQuerySpecificCode() {
jQuery.noConflict();
//more jquery code
jQuery(document.ready(function() {
//initialisetion code
}));
};
Loading from CDN means that many users will already have it in their cache. Also - the minified version is very small anyway.
Upvotes: 2