Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazyloading Google API not working

Here's the deal. I've tried a number of methods of lazy loading the Google Maps API JavaScript, and every time in do it, with any Lazy Loader I use, FireFox "blocks." It lazy loads just fine in Chrome.

What I mean by "blocks" is that the elements in the HTML don't display, and instead, the browsers spin trying to make a connection to download the Maps JavaScript.

The code follows. Put 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 "Open your console..." contents of the page, and the JavaScript is requested and downloaded, async, in the background.

In FireFox, the "Open your console..." contents never appear, and it hangs (status bar says "Read" from a Google DNS), never finishing or displaying the page contents.

like image 824
AgileMeansDoAsLittleAsPossible Avatar asked Apr 01 '26 23:04

AgileMeansDoAsLittleAsPossible


1 Answers

Are you sure you need to write your own loader? What about using a previously tested implementation: Lazy Load

like image 83
FreeAsInBeer Avatar answered Apr 03 '26 12:04

FreeAsInBeer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!