loading javascript dependencies on demand

后端 未结 6 1610
灰色年华
灰色年华 2020-12-14 23:15

I\'m sure there are different approaches to this problem, and I can think of some. But I\'d like to hear other people\'s opinion on this. To be more specific I\'ve built a w

6条回答
  •  眼角桃花
    2020-12-15 00:04

    The Google AJAX APIs provide dynamic loading for Google's JavaScript APIs. There is an example of loading the Maps JS on-demand in the documentation:

    function mapsLoaded() {
      var map = new google.maps.Map2(document.getElementById("map"));
      map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
    }
    
    function loadMaps() {
      google.load("maps", "2", {"callback" : mapsLoaded});
    }
    

提交回复
热议问题