Soft jQuery Loading

25 просмотров
Перейти к первому непрочитанному сообщению

Sean B. Palmer

не прочитано,
4 апр. 2010 г., 08:42:2504.04.2010
– Gallimaufry of Whits
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.

Sean B. Palmer

не прочитано,
18 нояб. 2010 г., 09:45:2818.11.2010
– Gallimaufry of Whits
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/

Dave Pawson

не прочитано,
18 нояб. 2010 г., 09:57:2018.11.2010
– wh...@googlegroups.com
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

Pererinha

не прочитано,
18 нояб. 2010 г., 10:31:3018.11.2010
– wh...@googlegroups.com
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

Dave Pawson

не прочитано,
18 нояб. 2010 г., 10:36:5818.11.2010
– wh...@googlegroups.com
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

Sean B. Palmer

не прочитано,
18 нояб. 2010 г., 11:56:0718.11.2010
– wh...@googlegroups.com
> 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!

Pererinha

не прочитано,
18 нояб. 2010 г., 11:58:3118.11.2010
– wh...@googlegroups.com
oh,
now I read the old thread, and it makes sense

=)

thanks for the explantion

Dave Pawson

не прочитано,
18 нояб. 2010 г., 11:58:5518.11.2010
– wh...@googlegroups.com
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

Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений