What is the difference between the two Google JS c

2020-06-23 09:06发布

A) <script src="https://apis.google.com/js/api:client.js"></script>

versus

B) <script src="https://apis.google.com/js/client.js"></script>

The only differnence being the api: before client.js.

CDN A is used in the Google Sign-In for Websites docs in the Building a button with a custom graphic section.

CDN B is used almost in the Google API Client Library for JavaScript (Beta) docs.

They both appear to work interchangeably.

2条回答
Summer. ? 凉城
2楼-- · 2020-06-23 10:00

Use links only from the documentation!

Simple to check this:

1) Add to header of your page this script:

<script src="https://apis.google.com/js/client.js"></script>

Open DevTools -> Network I see:

for client.js

2) Change link to other script

<script src="https://apis.google.com/js/api.js"></script>

Open DevTools -> Network

I see:

enter image description here

api.js is the core, when client.js is the module.

Here a completely different content: https://apis.google.com/js/platform.js

查看更多
一纸荒年 Trace。
3楼-- · 2020-06-23 10:08

Short answer: there is no difference

Long answer:

The Google JS client CDN is a bit weird because the actual JS you get is dynamically created based on the file name you provide. You can load multiple components of the library by constructing the URL as module1:module2:module3.js

api is the core part and is always loaded even if you don't add it to the list of modules, because it handles loading the other modules.

Theoretically you could just include api.js and then dynamically load extra modules by calling gapi.load("module", callback) which is exactly what happens when you load api:client.js or just client.js

If for example you would want to use the API Client Library together with the new sign-in methods you could include api:client:auth2.js or client:auth2.js.

And for extra confusion you could even include https://apis.google.com/js/.js which is the same as https://apis.google.com/js/api.js

查看更多
登录 后发表回答