Soft jQuery Loading

Showing 1-8 of 8 messages
Soft jQuery Loading
Sean B. Palmer
04/04/10 05:42
The Problem: When saved locally, an HTML file has no jquery.js.
The Solution: Check for local jQuery, otherwise use a web version.

This code works:

<script src="jquery.js"></script>
<script>
if (typeof jQuery == 'undefined') {
   src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'
   document.write('<script src="' + src + '"></scr' + 'ipt>')
}
</script>
<script>
[jQuery here]
</script>

But it contains a document.write, which is generally frowned upon. The
following version doesn't use document.write, but it also doesn't
work, despite there being no obvious reason why it shouldn't:

<script src="jquery.js"></script>
<script id="check">
if (typeof jQuery == 'undefined') {
   var e = document.createElement('script')
   e.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'
   var check = document.getElementById('check')
   check.parentElement.insertBefore(e, check.nextSibling)
}
</script>

I suspect that it needs to do the $(document).ready thing that jQuery
does, but of course since this code is meant to load jQuery it can't
be used directly.

Re: Soft jQuery Loading
Sean B. Palmer
18/11/10 06:45
Better solution, derived from html5boilerplate.com:

<script src="http://goo.gl/LISf" title="jquery.js"></script>
<script>
if (!window.jQuery)
 document.write(unescape('%3Cscript src="jquery.js"%3E%3C/script%3E'))
</script>

--
Sean B. Palmer, http://inamidst.com/sbp/

Re: Soft jQuery Loading
DaveP
18/11/10 06:57
Rather enigmatic Sean?
Better than .... ?

regards DaveP

> --
> Comment at http://groups.google.com/group/whits/topics
> Subscribe to http://inamidst.com/whits/feed
>

--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

Re: Soft jQuery Loading
Pererinha
18/11/10 07:31
I guess it is better than use jquery.js of you own website, right?
by using the jquery hosted by google the js file will be loaded faster because the google has multiple geographic servers and you (user) will be redirected to the one that is near from you
Re: Soft jQuery Loading
DaveP
18/11/10 07:36
On 18 November 2010 15:31, Pererinha <pere...@gmail.com> wrote:
> I guess it is better than use jquery.js of you own website, right?
> by using the jquery hosted by google the js file will be loaded faster
> because the google has multiple geographic servers and you (user) will be
> redirected to the one that is near from you

Thanks Pererinha, makes sense now.


regards

--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

Re: Soft jQuery Loading
Sean B. Palmer
18/11/10 08:56
> Better than .... ?

Oh, this is a reply to an old Whits thread:

http://groups.google.com/group/whits/t/77cd2f9ea5f079a4

I just hit reply to the original message that I sent, and figured it
would come up nicely threaded for anyone on the mailing list. Guess it
doesn't work for people who joined after the original message was sent
though!

--
Sean B. Palmer, http://inamidst.com/sbp/

Re: Soft jQuery Loading
Pererinha
18/11/10 08:58
oh,
now I read the old thread, and it makes sense

=)

thanks for the explantion
Re: Soft jQuery Loading
DaveP
18/11/10 08:58
On 18 November 2010 16:56, Sean B. Palmer <s...@miscoranda.com> wrote:
>> Better than .... ?
>
> Oh, this is a reply to an old Whits thread:
>
> http://groups.google.com/group/whits/t/77cd2f9ea5f079a4
>
> I just hit reply to the original message that I sent, and figured it
> would come up nicely threaded for anyone on the mailing list. Guess it
> doesn't work for people who joined after the original message was sent
> though!

I'm getting these as gmail emails, i.e. no threading?
Oddities of 'new' email modalities?

[Actually my first reaction was 'sbp has finally cracked' :-)]
Kidding Sean.

regards

--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk