4

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.

Marc M.
  • 3,631
  • 4
  • 32
  • 53

2 Answers2

21

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

Scarygami
  • 15,009
  • 2
  • 35
  • 24
3

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

tanguy_k
  • 11,307
  • 6
  • 54
  • 58
artamonovdev
  • 2,260
  • 1
  • 29
  • 33
  • 1
    This is very useful. Is there any documentation about the differences between client.js, platform.js and other libraries, and when I need which ones? Shoud I just load `api:client:platform.js` if I want to use authentication and access my own cloud endpoint? – rakensi May 03 '17 at 10:01
  • @rakensi you can view this sample (https://developers.google.com/api-client-library/javascript/samples/samples). When we use only api.js then others libraries like client api downloads asynchronously. Quote from the documentation: """The gapi.client.init function lazily loads auth2 if it is needed. If you are sure your app needs auth, loading the two modules 'client:auth2' together before you call gapi.client.init will save one script load request.""" – artamonovdev May 12 '17 at 17:38
  • 1
    Thank you, artamonovdev. I wish Google would document the javascript clients more clearly. I now use the undocumented `gapi.client.load(name, version, callback, apiRoot)` to load my own library, which I hope will continue to be possible as the 3-parameter method `gapi.client.load` is deprecated. The samples you refer to are sometimes helpful, but I would rather have comprehensive API documentation. – rakensi May 14 '17 at 08:14