0

I'm loading the Google Maps API using jquery $.getScript like so

$.getScript("https://maps.googleapis.com/maps/api/js?async=2&callback=GMapsInit");

You can see that the URL has the callback function GMapsInit. Does the GMapsInit function get called after the script is loaded and executed, or simply after its loaded and not necessarily executed?

2
  • Do you encounter any issue? Commented Nov 8, 2015 at 18:39
  • Nope. No issues at all Commented Nov 8, 2015 at 19:48

1 Answer 1

1

The callback is called when the script is loaded AND executed.

This is why you have to use a callback when you load Google Maps.

Sign up to request clarification or add additional context in comments.

5 Comments

It could be executed before any async operation in script included BUT i'm not sure there is any
also why you can't give a closure as a second argument to $.getScript() The success getScript() callback will be called after the callback set in URI jsfiddle.net/p6gp13ju
But the GMapsInit() function is already being called in the URL. What would adding this do exactly?
Well if it works as @A. Wolff said, you don't need to put a callback int the URL. You just put your code in the closure with the get script. It's one solution or the other, it's just a matter of what you prefer.
@PeterPan666 ya exactly but i'd suggest to use the callback url parameter instead because this is how, i suppose, works this API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.