64

Google's CDN is nice, but it's not 100% reliable for all users. It occasionally fails to load for me. Other users have had trouble with it due to sloppily-configured networks, and some may prefer to block external scripts by default.

It's one more possible point of failure. It would be preferable if Stack Exchange didn't depend on it.

If you don't want to stop using it, consider adding a fallback if it fails to load. Something like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
  if (!window.jQuery) {
    document.write('<script src="https://cdn.sstatic.net/stackoverflow/content/js/jquery-1.7.1.min.js"><\/script>');
  }
</script>
3
10

I dislike this proposal cause it cascades.

What about cdn.sstatic.net? Should we add a fallback to sstatic.net? Perhaps the network is totally disallowing remote resources, what about a second level fallback to stackoverflow.com?

What happens if downloading stuff from Google is taking 30 seconds to time out? Now the fallback is going to be mega delayed.

Personally, I see no advantage in using the Google CDN, our CDN outperforms it usually. With the advantage that the connection can be reused later on in the request. Less CDNs = Less randomness.

Additionally I feel a better investment of our resources would be pushing jQuery to load async, so you can still see the content even if jQuery is not loaded. (Question/Show page does this partially.)

Now, some may say that Google CDN version of jQuery is incredibly likely to already be on a machine, the reality is that 20% of our page views have an unprimed cache, empty cache is incredibly likely. People are often clicking "refresh" as well forcing a If-Modified-Since to Google as well.

10
  • 7
    Sure, using cdn.sstatic.net instead of Google's CDN also sounds good to me. It doesn't matter if we can load jQuery when we can't load the scripts that use it. +1
    – Jeremy
    May 28 '12 at 3:51
  • 4
    As an aside: showing a warning when sstatic.net fails to load might also be easily achieved? That's already nicely done for jQuery, but that very check is in code loaded from sstatic.net. So, a warning for sstatic.net needs code from the regular domains themselves.
    – Arjan
    May 28 '12 at 5:15
  • 2
    Just curious: "the reality is that 20% of our page views have an unprimed cache" — were you actually somehow measuring the availability of jQuery for those requests?
    – Arjan
    May 24 '14 at 15:21
  • 3
    @waffles, I disagree with your first paragraph. The proposal does not need to cascade because there's nothing stopping it from being treated as a case-by-case basis. The question would be whether there's a real observed problem with a majority of visitors. And as for Google's CDN, there's actually such a real problem. Also see Use of ajax.googleapis.com not China friendly.
    – Pacerier
    Jul 14 '15 at 5:41
  • @Pacerier waffles has left the building best as nickcraver or flag it or something
    – waffles
    Jul 15 '15 at 6:32
  • @waffles, Btw what's the reason for your retirement?
    – Pacerier
    Aug 5 '15 at 9:24
  • 1
    @Pacerier too much maple syrup.
    – waffles
    Aug 5 '15 at 9:25
  • @waffles, Ok.. I'd not quite have the context here..
    – Pacerier
    Aug 5 '15 at 10:05
  • 1
    @Pacerier I wrote a blog post about why I left years ago, not really on topic here.
    – waffles
    Aug 10 '15 at 5:31
  • 2
    @waffles Well, it is six years later and none of the potential downsides/fears by having a fallback in place you wrote about have (permanently) materialized. I simply can't understand the logic to sit around and do nothing while the site is horribly broken from China.
    – Bob Jordan
    Feb 24 '18 at 5:23
9

I think this is a good idea. As a Chinese visitor I'd like to use jQuery CDN from baidu.The URL is https://libs.baidu.com/jquery/1.11.1/jquery.min.js

3
  • 3
    Hey, this brings me to an idea. Why not do that with Greasemonkey and let it do some interceptions? In clear print, intercept SE's request to Google CDN and use the Baidu one instead when we're surfin' in from *.cn. Can't be rocket science to implement. I would even do it myself; but simulating a client from China is simply not the same as connecting on location. Because what I've seen so far in statements from the staff means to me that rather hell freezes over than they'd ever agree on implementing a fallback for Chinese visitors. Jan 28 '16 at 15:56
  • 4
    Why can't we use a local copy of jquery?
    – user393619
    Jun 23 '18 at 12:07
  • 2
    Slightly late, but you could use decentraleyes. It's available for Firefox, Chrome, and Opera, and loads some scripts that usually rely on CDN's (like jquery) from a local repo instead. I use it to speed up sites, but I'd imagine you could use it to avoid having sites blocked for common scripts in CDN's that for some reason aren't available (temporary/permanent outage, blocked on the network, etc). It won't help for general SE scripts (as they're site-specific and aren't included), but it'll at least help avoiding jquery issues. SE works without JS too btw. Dec 15 '18 at 14:53
4

Here's a practical solution for users: Fortunately there's this addon called LocalCDN that works exactly as its name suggests: It blocks those requests to CDNs and loads up those resources locally, hence this makes loading up jQuery possible even when ajax.googleapis.com is blocked or unreachable.

enter image description here

Not only is this better for unbreaking StackExchange on those networks, but also for speed (especially on that poor 4G network that my mobile phone uses with that addon installed on Firefox Nightly, bonus I get to save some Mbs of bandwidth as well and I cannot stress how much my mobile 4G browsing experience has improved since I adopted that addon) but it also protects your privacy from those spooky "free" CDNs.

The addon is free and completely open source (there's even an auditing script to verify the integrity of the bundled resources) and I would encourage everyone to give it a try. Anyway hope at least someone will find this useful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .