1

I was clicking around Meta Stack Overflow earlier and suddenly ran into a page with a big red error message at the top, "Meta Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.":

Meta Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.

Looking at the error log, I saw Undefined ReferenceError: $ is not defined.

Undefined ReferenceError: $ is not defined

So it looks like jQuery failed to load. Being at work when this happened, I got distracted by something work-related and by the time I came back to continue my investigation of this, I realized I had accidentally closed the browser tab, so I didn't get a chance to look at the developer tools "Network" tab and confirm my suspicion that the Google CDN failed to serve jQuery. But it still seems likely. Especially considering the error is coming from "stub", which is included right after jQuery:

jQuery including

So, since you're not using an asynchronous script loader here, it would be easy to implement a piece of code that falls back to a local copy of JavaScript code in the case where Google's CDN fails. Something like this:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="/content/js/query.min.js"><\/script>')

Is it a good idea?

1
  • 1
    Doh, I'm sure this dupe showed up in the "may already have been asked" box and I just completely failed to see it...
    – Ben Lee
    Jul 17, 2013 at 23:35

0

Browse other questions tagged .