Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best fallback if Google Ajax API is not available (since Google does not permit to install it locally)?

In my site I have:

...
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
...

The script above is the Google script to load up other resources dynamically. (eg Google charts API)

This works 99.99% of the time. However, I just got a client that for some reasons got his company restricting access to google.com.

As a consequence of this my website simply threw a JavaScript error.

Now I know how to handle that, and I can check if window.Google exists. but my question is

"what's the standard way to deal with this? "

In other words if you embed 3rd party JavaScript how best do you deal with their JS not available?

NOTE: VERY IMPORTANT

You can not host the chart code locally or on an intranet.

SEE FAQ from Google: https://developers.google.com/chart/interactive/faq#localdownload

Can I download and host the chart code locally, or on an intranet?

Sorry; our terms of service do not allow you to download and save or host the Google.load or Google.visualization code.

like image 371
Zo72 Avatar asked Oct 29 '12 11:10

Zo72


People also ask

What is Google Ajax API?

The Google AJAX Search API is designed to make it easier for webmasters and developers to do two things: Add a dynamic search box to your site that includes Google Web, Video, News, Maps, and Blog search results. Build powerful web apps on top of Google search. See some samples.

Does Google use jQuery?

No, Google certainly does not use jQuery—it is all vanilla JavaScript and (sometimes) Closure Library. As for inlining, if JS/CSS is relatively small, it is faster to inline it to minimize the number of HTTP requests. Google Page Speed Online can give you some tips on how to optimize your page.


2 Answers

There is no real alternative. Due to Google's terms of service you cannot use Google API without access to google.com.

  • Check the connection to Google and iform user that function is not available
  • Develop your own or use non-google api. Still you can use Google if available
like image 131
Jan Pfeifer Avatar answered Sep 22 '22 01:09

Jan Pfeifer


The solution is that your client's company review their content filtering policies. Google are quite clear in their previous answer concerning offline access:

…your computer must have live access to http://www.google.com/jsapi in order to use charts.

You are using a third-party solution according to their terms and conditions, which naturally imposes limits on how that solution may be used by your clients. You need to stand firm or find a more liberally-licensed solution. (At any rate, you are more likely to succeed at convincing your client's IT department than petitioning Google to change their TOS.)


For the more general case of third party JS APIs that may not load but for which you are allowed to keep a local copy on your server, see this question.

like image 32
Jordan Gray Avatar answered Sep 21 '22 01:09

Jordan Gray