Question

I've been using Google Jsapi like so:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.3");
</script>

But the Google docs recommend doing this:

<script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_KEY_HERE"></script>
    <script type="text/javascript">
        google.load("jquery", "1.3");
    </script>

In my experience, it seems to work whether you include the key or not.

Will I encounter any problems if I don't use a key?

Was it helpful?

Solution

I would say that if the documentation says you need to include it, then you should include it. They may start enforcing that rule with no further notice, and your application may stop working.

If you restrict yourself to following the public API, you should be safe from Google changing their service, and your application breaking.

That advice holds for any other non-public APIs as well.

OTHER TIPS

I don't think you need it for loading libraries such as jQuery, but the same loader is used for several other APIs such as Google Maps, which may require a valid API key.

Also, this is what Google has to say about using a key:

The API key costs nothing, and allows us to contact you directly if we detect an issue with your site.

As of today (February 2012), the API key is not even longer mentioned in the dev guide:

http://code.google.com/apis/libraries/devguide.html

And also:

The preferred method is to load the libraries via standard tags (as in , which will result in the fastest loads.

That means that it's not even necessary to load google jsapi, but you can simply:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

However, with google.load you can:

always load the latest stable version of the API, request the version number without specifying a revision. So, using the above example, requesting version 2 loads the latest stable revision of the API, e.g., 2.2.3.

Although I'd argue, that is a dangerous feature, since an upgrade of any library has to be tested before going live.

If you choose to load libraries with google.load, you also need to set google.setOnLoadCallback.

Example:

google.setOnLoadCallback(function() {
    google.load("jquery", "1.7");
});

To sum up: in both cases an API key is not needed any more, the script tag to load a library directly is faster, simpler and also recommended by Google.

As of May 2012, the Google Loader no longer requires keys:

https://developers.google.com/loader/signup

Please also note that there is a distinction between the Google Libraries API

The Google Libraries API is a content distribution network for the most popular, open-source JavaScript libraries.

and the Google Loader.

Google API loader allows you to easily import one or more [Google] APIs, and specify additional settings (such as language, location, API version, etc.) applicable to your needs.

the reason for asking you to include a key is so Google can more easily track usage of their API - so if you have a very popular app, google will notice and possibly do work to modify the API such that it will work better in the future.

personally I never use them because they make my code look ugly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top