Steven,
you may give this a try too, this in the spirit of reusing what we
already have available in browsers:

<script id="loader" src="somecdn.com/jquery.js"
onerror="this.src='local/jquery.js'"></script>

The "onerror" event hook should be available and usable on current
browsers and it allows you to have more complex function being called
handling the error, maybe with multiple retries.

<script id="handler">
function handler(script) {
   ... your stuff here ...
   // get a reference if you prefer
   //var script = document.getElementById('loader');
   // or just used the passed argument
   script.src = 'local/jquery.js';
   .... your stuff here ...
}
</script>
<script id="loader" src="somecdn.com/jquery.js" onerror="handler
(this)'"></script>

Hope it can be another bullet for your weapons ;-)

Diego


On 10 Ott, 02:54, Steven Black <ste...@stevenblack.com> wrote:
> First of all, thanks @jresig because that's just way too elegant.  I
> was anticipating something far more complex.
>
> A couple of questions:
>
> Ifhttp://cdn/jQuery.jsfails, we want the local-domain jQuery.js to
> load next, BEFORE the any other subsequent script which is likely a $
> (function(){}) or a call for plugin, both of which have a jQuery
> predicate.  So I don't sense that Phil's ...('head')[0].appendChild
> (script) would work reliably.  Am I wrong about that?  Does this
> really work as you expect, Phil?  I would expect a prependChild(), no?
>
> Second, Dave raises another crux of the matter: we need to bail to the
> failover ASAP, ideally within a second or two.  It's almost as if we
> need the CDNs to also provide a sub-packet-sized package we could
> request, wrapped inside a very short timeout to bail to the failover.
>
> **--**  Steve
>
> On Oct 9, 9:10 am, Dave Methvin <dave.meth...@gmail.com> wrote:
>
> > > I took this great idea and went ahead implementing it on a few sites I
> > > maintain using different syntax.
>
> > It's more than a syntax change; it's entirely different semantics.
> > Your version fetches a copy of jQuery asynchronously. If there is
> > a .ready() handler below that block of code, jQuery may not be loaded
> > by the time it is reached and you'll get errors. By using
> > document.write and a script tag, you can be guaranteed that the
> > browser won't proceed to run any code below it until it either loads
> > the script or gets an error back from the request (like a 404 or a
> > timeout).
>
> > I'd think the timeout situation is the most likely outcome when
> > Google'sCDNis down, which means the user will see a blank screen for
> > 30 to 60 seconds before it even reaches the document.write anyway. So
> > it seems like you'd need to load the GoogleCDNversion asynchronously
> > to prevent that. But that raises the question of what to show the user
> > while it's trying to find a reachable version of jQuery...

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to