views:

99

answers:

2

I want to incorporate a minified javascript library (for example http://sizzlejs.com/) into my own non minified javascript library. The reason is that my library plugs into other websites and I don't want to ask them to include the extra library (sizzle) as well.

Is there a way to include a minified library in a non minified library and have them both in one js file?

A: 

The simplest approach would be to just copy and paste the code from the minified library directly into the top of your file.

Micah
+1  A: 

You could just copy the sizzle code into your own code. That is, at the top or bottom of your js file. This is how jQuery include sizzle in their code.

Or you could dynamically add a script tag element to the "head" of the document in your own library which has src set to the sizzle minified file (look at how jQuery includes scripts in its AJAX routines for an example).

If you include dynamically, you might find that it's actually faster, as you can probably link to sizzle from the google servers, and the user may well have it already cached in their browser (jQuery actually recommend including their own library in this way)

Graza
To clarify what Graza's saying, you put code in your own library which, when loaded, modifies the head of the document into which it's loaded, and adds a new script tag which references the third-party library. So the actual HTML file only has one javascript import, but the imported file dynamically adds additional imports.
morgancodes