74

I often use Stack Overflow from China, where Google based services are regularly blocked or severely hampered.

I have noticed that as of late, I am getting a lot of the following error:

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

Thereby rendering Stack Overflow useless.

Looking at the Chrome console, I notice that the reason is as follows:

Failed to load resource: net::ERR_CONNECTION_TIMED_OUT http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js

Is is possible for Stack Overflow to host jQuery itself, therefore bypassing the Great Firewall of China?

If not, what is the reason for this?

10
  • 2
    This answer on MSE provides some insight as to why the Google CDN is used.
    – Bart
    Commented Jun 4, 2014 at 7:50
  • 6
    There's also this question and answer, which gives the (poor IMO) excuse as to why there is no fallback if ajax.googleapis.com is unavailable.
    – Matt
    Commented Jun 4, 2014 at 10:21
  • 5
    @Matt. I agree it is a very poor excuse - a Fallback can also be to another CDN . But anyhow see a solution here : meta.stackoverflow.com/q/270856/1244126 Commented Sep 12, 2014 at 0:51
  • 4
    Maybe this will be of help: decentraleyes.org
    – asmaier
    Commented May 11, 2017 at 8:58
  • 6
    What about people who are concerned about privacy? I'm using FF56+NoScript to filter remote code from scorecardresearch.com and other third parties from SO. When browsing, it should be my choice whose remote code may run on my computer. Whether SO even works and how it works totally depends on Google. This must be a political choice, I can't believe it's lazyness. Seriously, how hard can it be to host jQuery locally, just like all other resources on SO?
    – Code4R7
    Commented Nov 17, 2017 at 10:25
  • 4
    @asmaier, I like the idea of decentraleyes.org, but it needs permission to: access your data for all websites, read and modify privacy settings, store unlimited amount of client-side data, access browser tabs and access browsers activity during navigation. And who do I trust all that? whois decentraleyes.org tells me that would be WHOISGUARD, INC. in Panama. Think twice.
    – Code4R7
    Commented Nov 17, 2017 at 10:33
  • 3
    @Code4R7 The registrar of the website decentraleyes.org has nothing to do with the offered plugin. The plugin is opensource and can be found on github.com/Synzvato/decentraleyes . So the person behind this is even known by real name, see github.com/Synzvato . You should also read the privacy policy "Decentraleyes does not collect any data of any kind.", see github.com/Synzvato/decentraleyes/wiki/Privacy-Policy . Please think thrice.
    – asmaier
    Commented Nov 17, 2017 at 21:39
  • @asmaier Your links should have been on that site. The privacy policy is the best I've ever seen. The tool is a great concept. I'm ready to give it a try.
    – Code4R7
    Commented Nov 18, 2017 at 11:06
  • 2
    Good question...I still wonder why developers can't make request route to another CDN as backup if there is no response from Google CDN. This will open gateway to millions of Chinese developers. The collaboration will be awesome.
    – foobar
    Commented Aug 16, 2019 at 10:06
  • While there might be issues in China I want to point out that there are serious privacy concerns in using google services in general. I personally keep google services blocked as much as ever possible and appreciate pretty much that at least there's a 'use an alternate source' link!
    – Aconcagua
    Commented Jul 31, 2023 at 10:30

4 Answers 4

22

Technically, there are several possible ways to solve the CDN problem.

  1. Replace the CDN hosted on google by another CDN that's not linked to Google. This includes for example, MAXCDN used by https://code.jquery.com/ itself. (There is also a feature request about this Replace ajax.googleapis.com). These alternatives and China probably do not have quarrels with each other and they are not likely to get blocked.

  2. Use an alternative CDN such as MAXCDN as a backup CDN. When the google-hosted CDN fail, fall back to the backup CDN. A popular SO question Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail, and the answers therein (among others) show how that can be done in JavaScript and HTML5.

  3. hosting jQuery locally. Although reliable, this is not preferable performance-wise as pointed out in other answers provided or linked here.

  4. If the SO idea is popular enough, probably a website similar to SO will be developed within the firewall.

Of course, whether this works depends on other factors.

  1. some of identity/credential providers are blocked: Google, Facebook, (and OpenID in the past). So the users in China may only be able to register a native SO account.

  2. the demand for using SO from China. A meta question here What's up with China? seems to suggest that there is a surge recently.

  3. the resources and manpower available in SO to resolve this particular problem.

7
  • 3
    Your (4.) makes no sense. Users without access to ajax.googleapis.com will not be able to upvote anything nor leave a comment. So users which are actually affected by this problem will remain unheard on this platform unless they know how to work around this problem (I'd assume that's the minority).
    – josch
    Commented Nov 10, 2016 at 6:09
  • 3
    A website similar to SO has already been developed. It plagiarized almost everything - including (almost) all badges (no bounty there, though).
    – iBug
    Commented Dec 5, 2017 at 10:27
  • 4. How more popular could SO get than it already is? Given the symbiotic relationship between SO and Google (the former providing a lot of search traffic in easily digestable format, the latter crawling SO ten times a second and being relied on as the primary search method for the whole of SO), I believe there must be deal saying SO is not functional without resoursces loaded from Google. Technically and gicen the typical user profile the benefit from cached jQuery from Google is negligible on both sides.
    – Pavel
    Commented Jan 14, 2019 at 20:26
  • 3
    Actually, number 3 isn't just possible, there's a plugin for the three major browsers (Firefox, Chrome, and Opera) that does exactly that. I use it to speed up page load speeds (and it does a great job at that), but because it loads it locally, it bypasses the Google CDNs and would enable full functionality where Google for some reason is blocked. This question also mentions a plugin called resource override that could help (although it appears to be manual). The point being, there are ways to solve it without SE. Commented May 31, 2019 at 15:40
  • "If the SO idea is popular enough, probably a website similar to SO will be developed within the firewal" If China continues to block SO indirectly via googleapis, that would actually make sense. They could also use the content from here (and even give attribution, making a link to a blocked site) and start from there. I wonder if something like this maybe already happened and outside of China simply nobody knows of it. Commented Aug 19, 2019 at 14:22
  • In 2020, this is a non-answer. SO already has a CDN for static files (sstatic.net) and it can be cached indefinitely using cache-busting methods. It would remove an entire DNS query and TLS connection. Besides the overhead with creating a TLS connection, the DNS record for ajax.google.com has a 60 second TTL. With HTTP/2, and a already needed connection to sstatic.net this file could be multiplexed loaded with the other JS files without needing another TCP connection and DNS query. The file should be moved for performances reasons alone. Commented May 15, 2020 at 17:18
  • About the credential providers: From a privacy point of view best you can do is having a native account anyway ;)
    – Aconcagua
    Commented Jul 31, 2023 at 10:33
17

As one of our developers explains:

For technical reasons, we use the Google CDN for the jQuery files (a CDN is a Content Delivery Network - a bit of technology that makes distributing things like images and JavaScript libraries across the world faster) - that's what is hosted on ajax.googleapis.com. This is something many many sites do and as result many people will already have this library on their computer.

It turns out that it's almost impossible to Sign Up at SE at China because another script is also blocked. China even blocks (intermittently) parts of our login system that we host ourselves. As a result, most users in China will be better off using a VPN.

As China (and other countries inclined to block portions of the internet), plugs other holes, other external dependencies would need to be self-hosted as well. This doesn't seem like a good use of resources.

23
  • 35
    I'm not going to make flames. But I think, don't make google like a lady standing still there and let visitors to approach her. Maybe we took it for granted, we depend much more than necessary on google. Why stackoverflow.com not called stackoverflow.google.com? why must a script should host on google? where is the freedom of network turned so centerized? In fact, is it good to use Google CDN outside google?
    – neoedmund
    Commented Nov 10, 2014 at 14:07
  • 3
    @neoedmund It's good to use it because of the much higher likelihood of a user having it cached, thereby reducing their page load times.
    – Nick Craver Mod
    Commented Mar 12, 2015 at 22:09
  • 5
    hola.org seems to be blocked in China. As a result, most users in China just facing this problem now will be no better off after reading this "answer". Commented May 31, 2015 at 13:53
  • 8
    @neoedmund I fully agree with you. This makes us yet more dependent on Google and their server farms, which have conquered the whole world already anyway. And it goes on...It's just a few (hundred?) lines of JS code, nothing too spectacular. So even with 100k users per minute, this sort of "load" should be digestible on SO locally with no problems. It's just a matter of stubbornness IMHO. Commented Jul 4, 2015 at 1:34
  • 1
    @NickCraver Is there any recent evolution regarding China (and/or Stack Exchange jQuery file service)? quantcast.com/stackoverflow.com shows that the last 2 weeks, china visitors have gone from 50-80K to... 790K two day ago!?
    – VonC
    Commented Jul 31, 2015 at 5:54
  • 7
    @NickCraver a "feature" which may possibly reduce page load times for some users, which also with 100% certainty disables the site for other users... this is a very questionable decision. I've never worked at a company with a commercial product where that was an acceptable trade-off. (Especially given that it's very likely there are other options available to achieve the same benefit.)
    – michael
    Commented Nov 1, 2015 at 7:39
  • 12
    I don't understand this answer. As If Google CDN is the only CDN on the planet. Microsoft CDN is not blocked and works fine for JQuery at least.
    – Sebastian
    Commented Nov 3, 2015 at 5:44
  • 4
    @SebastianGodelet And what happens when Microsoft's CDN gets blocked, and then MAXCDN, and then every other CDN on the planet? The problem is with the Chinese government, not Stack Overflow or their CDNs.
    – Ian Kemp
    Commented Nov 16, 2015 at 7:36
  • 3
    Of course the problem is on the government side, but the fix for this is in SEs hand. For now, it is just an artificial restriction due to a simple implementation detail. Note that Microsoft so far complies with the gov', s.th. they can operate in within China, Google chose to not comply, hence the blocking.
    – Sebastian
    Commented Nov 18, 2015 at 5:15
  • 3
    Google sets a max-age of 365 days with a 30 day stale-while-revalidate cache on jQuery. Stack Exchange could easily do the same. The performance difference between hosting this on Google's CDN vs. internally on SE is minimal and would only be realized by users who either clear their cache daily or never visit the site. For users who clear their cache often, they would welcome this change as it is one less signal to google. I personally use Decentraleyes to block google CDN. It would also help Chinese users, and be one less DNS query & server that can have outages. Commented Aug 16, 2017 at 17:56
  • 1
    @NickCraver and Jon Ericson, please revisit Jeff Atwood rejection to fallback to a secondary source when the primary one is blocked. It's been 10 years! Google is still blocked in China. And there are technical solutions for that issue that would help hundreds of millions of visitors.
    – Cœur
    Commented Jan 31, 2019 at 5:54
  • 1
    "This doesn't seem like a good use of resources." Is this still the estimation in 2019, especially from a management point of view? More customers in China sound like it could be a good thing compared to the relatively low effort required here. Commented Aug 16, 2019 at 9:35
  • 1
    @Cerbrus But that would only be a one time effect. Maybe SE could change the CDN only for visitors from China as some kind of compromise. There are millions of programmers in China and probably many of them speak English by now. I wonder if the estimation by the company changed in the last five years. This answer could be outdated. Commented Aug 16, 2019 at 10:43
  • 1
    Making assumptions about a user's location sounds like a very ugly hack... Switching CDNs would guarantee every visitor to the site, now and for the remainder of time, would have to download that file. Then SE might as well not use a CDN.
    – Cerbrus
    Commented Aug 16, 2019 at 10:45
  • 1
    @JonEricson I don't really understand why China would like to block StackOverflow. It contains zero politics but lots of programming knowledge. There is some chance this is just a collateral damage. Anyway, I had the idea of making a static site with selected content from StackOverflow for a long time. If I ever come around doing it, I can pay attention to not using CDNs and if then additionally there are significant amounts of Chinese visitors, I can report back. Commented Aug 17, 2019 at 12:13
10

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 making loading up jQuery possible even when ajax.googleapis.com is blocked.

Enter image description here

Not only is this better for unbreaking Stack Overflow/Stack Exchange 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. A bonus is I get to save some Mbit/s 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, I hope at least someone will find this useful.

2

China-friendly solution: jsDelivr. They have an ICP license and works reliably in China. Popular resources like jQuery and Bootstrap are available at ease (from NPM) and I just migrated my personal website from Cloudflare's CDNJS to jsDelivr.

Disclaimer: I'm not affiliated with jsDelivr.

You must log in to answer this question.

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