Google Map · Javascript · RequireJS

RequireJS add Google Map API as dependencies with Async

Adding Google Map API to your webpage is easy, just load it as a script like below.

<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">

Notice the URL doesn’t end with .js extension; that confuses RequireJS that assumes all scripts end with .js. So you can use Async RequireJS plugin to load Google Map Api.

define(['async!https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY'],
    function () {
    });

Cheers – Sy

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s