Lazy loading google map api

I want to be lazy to load all third-party JS / CSS after displaying my home page, because there are external plugins, etc. used when the user navigates from the home page to a specific module.

So far I have managed to use the usual external .js and .css thanx libraries for http://wonko.com/post/lazyload-200-released

However, this fails for a path such as http://maps.google.com/maps/api/js?sensor=true

the code:

   LazyLoad.js('http://maps.google.com/maps/api/js?sensor=true', function () {
   alert('Your JS has been loaded');
   });

I think the solution would be how lazy-load web url?

0
source share
2 answers

I believe you need something like:

$.getScript('http://maps.google.com/maps/api/js?sensor=true');

jQuery. API . , Google - , , . .

0

: URL: 'http://maps.google.com/maps/api/js? Sensor = true' main.js. getScript sensor = true google, .

  var t=setTimeout(function(){
    jQuery.getScript('http://maps.google.com/maps/api/js?sensor=true');
    jQuery.getScript('http://maps.gstatic.com/intl/en_us/mapfiles/api-3/10/20/main.js');
  },1000);
-1

Source: https://habr.com/ru/post/1794789/


All Articles