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.
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.
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.
There is no real alternative. Due to Google's terms of service you cannot use Google API without access to google.com.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With