Should I link to Google API's cloud for JS lib

2019-01-06 16:01发布

I'm looking for the pros/cons of pulling jQuery & other JS libraries from Google API's cloud as opposed to downloading files and deploying directly.

What say you?


My decision

The likelihood of the lib already cached on the users system is the overriding factor for me, so I'm going with a permalink to googleapis.com (e.g. ajax.googleapis.com/ajax/libs/…). I agree with others here that loss of access to the Google server cloud is a minimal concern.

9条回答
走好不送
2楼-- · 2019-01-06 16:34

Pros:

  • Google's connectivity is probably way better than yours
  • It's a free CDN (content distribution network)
  • Your webapp might load faster, since you're using a CDN

Cons:

  • If/when you need to optimize by repackaging a subset of that third-party JS library, you're on your own, and your webapp might then load slower
查看更多
祖国的老花朵
3楼-- · 2019-01-06 16:34

The pros are quite obvious and are in the other answers :

  • you save bandwidth
  • google is probably more reliable than your server
  • probably cached in most browsers (anyone stats on this ?)

But the cons can be very tricky :

  • If you are using https, you will get an error on most browsers as your certificate isn't valid for google's domain, only yours. This is a major issue for https.
查看更多
一纸荒年 Trace。
4楼-- · 2019-01-06 16:39

I've been looking at the real-world performance of the Google loader for jQuery, particularly, and here's what I've found:

  1. Google's servers are quick and plenty reliable.
  2. They are serving from a CDN, which means if you have a lot of overseas users they'll get much better load times.
  3. They are not serving gzipped files. So they're serving a lot more bytes than they need to.

If you know what you're doing in Apache, Lighttpd, or whatever you're serving files with, you could set your cache headers just like Google's and significantly reduce the amount of data your end user has to download by serving it from your own server. You could also combine your scripts at that point and reduce your overall HTTP requests.

Bottom line: Google's performance is good but not great. If you have many many overseas users then Google is probably better, if your users are mostly US-based and maximum performance is your concern, learn about caching, Etags, gzipping, etc. and serve it yourself.

查看更多
你好瞎i
5楼-- · 2019-01-06 16:40

Pro:

Google's Ajaxlibs offer a very fine-grained "version control" for the included libraries. You can enforce a certain version (e.g. JQuery 1.3.2) or automatically request the latest version from a certain branch (e.g. JQuery 1.3 series -> would currently deliver 1.3.2, but maybe soon 1.3.3).

The later has definitely has benefits: you'll profit from smaller bugfixes/performance improvements without breaking your scripts/plugins.

Maintaining such a multi-library repository on your own can become quite ressource intensive.

查看更多
SAY GOODBYE
6楼-- · 2019-01-06 16:45

Con

  • Users in countries embargoed by the U.S. (e.g. Iran) won't get a response from Google
查看更多
Rolldiameter
7楼-- · 2019-01-06 16:47

Pros: It may already be cached on the user's system. Google has big pipes. You don't pay for the bandwidth.

Cons: You now have two different ways for your site to become unavailable: A service interruption on your server or one on Google's server.

查看更多
登录 后发表回答