jQuery does provide a $.getScript function that replicates your
jsInclude functionality.

I've also written a quick snippet that you might find beneficial. It
does automatic script includes based on your other script tags. For
example, if you add the small plugin I wrote and have the following
script tag:

<script type="text/javascript" src="/path/to/jquery.js?
ui.jquery.min,footer.min"></script>

Once the document is ready, jQuery will backload

/path/to/ui.jquery.min.js
and
/path/to/footer.min.js

My script is located here: 
http://snipplr.com/view/10368/jquery-automatic-script-includer/

There's also some pretty decent "onDemand" loading libraries out
there, which you may also find useful: 
http://www.google.com/search?q=on+demand+javascript

On Feb 3, 12:09 pm, Sébastien Richer <sebastienric...@gmail.com>
wrote:
> Hi Jim and Eric,
>
> I did a bit of testing around, and what I found is that i I want to
> "include" a js file from my js code, I'll need to have that script
> end, before the .js is "loaded".
>
> So I tried a couple of things and the following now works :
>
> <script language="JavaScript" type="text/javascript">
>         function jsInclude(jsFile) {
>                 document.write('<' + 'script');
>                 document.write(' language="JavaScript"');
>                 document.write(' type="text/javascript"');
>                 document.write(' src="' + jsFile + '">');
>                 document.write('</' + 'script' + '>');
>         }
>
>         // jquery.js
>         if (typeof($) != "function") {
>                 // jquery.js not included... include it
>                 jsInclude("/_js/jquery.js");
>         }
> </script>
> <script language="JavaScript" type="text/javascript">
>         // jquery.cookie.js
>         if (typeof($.cookie) != "function") {
>                 // jquery.cookie.js not included... include it
>                 jsInclude("/_js/jquery.cookie.js");
>         }
> </script>
> <script language="JavaScript" type="text/javascript">
>
>         alert("Type1 : " + typeof($));
>         alert("Type2 : " + typeof($.cookie));
>
>         [...]
>
> So this "works", but on a scale from 1 to 10, on the ugliness of the
> whole thing, I think I'd give it a 8 or 9 hehe :)
>
> I'll probably send my jsInclude function in my main .js file... So
> I'll have two script like that, just sitting there... what you guys
> think ?
>
> (These events are occuring in the footer.jsp file of my site which is
> on every page.)
>
> Thanks for the help!
>
> On 3 fév, 09:19, Eric Garside <gars...@gmail.com> wrote:
>
> > Honestly, best practice here is to redo how you include javascript.
> > Sad, but true. :(
>
> > On Feb 3, 9:15 am, Jim D <nofxbassist1...@gmail.com> wrote:
>
> > > You could check whether or not $ is a function.  If jQuery has been
> > > included, typeof($) should return the string "function" otherwise it
> > > will return "undefined"
>
> > > On Feb 2, 11:32 am, Sébastien Richer <sebastienric...@gmail.com>
> > > wrote:
>
> > > > Hi,
>
> > > > I tried to search around for this but have'nt had any luck, so I'll
> > > > ask here :)
>
> > > > I use jquery.js on most of my sites. And most pages have it included
> > > > in the <head> part. But not all of my pages, some are very old.
>
> > > > Along with jquery.js, most pages also have jquery.flash.js.
>
> > > > Now I recently needed to add something to my footer (which is included
> > > > on every page) and I need to user jquery.cookie.js, and so jquery.js.
>
> > > > Since not "all" my pages have jquery.js, I included in my footer both
> > > > jquery.js and jquery.cookie.js.
>
> > > > The problem is that when I include jquery.js a second time, the
> > > > initial "instance" (?) seams to be forgotten and now my
> > > > jquery.flash.js seams to have stopped working. I get an unresolved
> > > > for flash().
>
> > > > Anyone had a similar issue ? (If I'm not mistaking this is an issue
> > > > only with the latest versions of jquery.js)
>
> > > > Any workarounds ?
>
> > > > My backup plan will be to go around "all" of my pages and change the
> > > > way I call .js files. I'll probably create a javascript.jsp file and
> > > > include that in all my pages and control it from there. bleh... find
> > > > and replace...
>
> > > > Thanks for the help !

Reply via email to