Google Lazyloading API not working

Here's the deal. I tried several methods for lazy loading the JavaScript Maps API of the Google Maps, and every time this is done, with any Lazy Loader that I use, FireFox blocks. These lazy downloads are simple in Chrome.

What I mean by “blocks” is that the elements in the HTML are not displayed, but instead the browsers are trying to create a connection to load Maps JavaScript.

The code follows. Place it in an HTML file and open it in your browser:

<html>
<head>
    <script type="text/javascript" src="http://github.com/rgrove/lazyload/raw/master/lazyload.js"></script>
</head>
    <body>
        Open your console. Wait for "entering debugger..." message.<br />
        You can't see me in FireFox, can you?
        <script type="text/javascript">
            // If I remove the `sensor` from the query string key and value, 
            // Google rejects the request and alert() does occur
            LazyLoad.js("http://maps.google.com/maps/api/js?sensor=false", function() {
                console.log("entering debugger...");
            });
        </script>
    </body>
</html>

In Chrome, I see the contents of "Open Console ..." on the page, and JavaScript is requested and loaded, asynchronously, in the background.

FireFox " ..." , ( "" DNS- Google), .

+3
5

, ? : Lazy Load

+1

Google ? API , ,

+1

, LazyLoad script, .:) , , ?

, , .

0
source

Yes, why reinvent the wheel. You seem to be using jQuery. try this plugin: Download image only when it is available for viewing?

0
source

Solution Found: Check URL: http://maps.google.com/maps/api/js?sensor=true 'You can find main.js. A simple getScript for sensor = true will not give the whole google object, so the next import will be required.

  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);

PS: A similar problem with the Lazy stream loading google map api

0
source

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


All Articles