How to import the external JS with callback function?

Viewed 9237

I am using Google API, based on their link I have to put the following script in the HTML file

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

The custom callback function is being loaded after the client.js is loaded successfully.

function callback() {
  var ROOT = 'https://your_app_id.appspot.com/_ah/api';
  gapi.client.load('your_api_name', 'v1', function() {
    doSomethingAfterLoading();
  }, ROOT);
}

I would like to

  1. Separate HTML with JS file
  2. I downloaded the client.js file and put it in my local repo. But for reducing web request I would like to concat the client.js with other JS file. But I have no idea how to load the content with the concatenated JS file with the callback is being called

Thanks in advance

3 Answers
Related