views:

2819

answers:

4

Hello.

I am using Google Maps API to display a map on a certain page.

Problem is that the file http://maps.google.com/maps?file=api..... sometimes happens to load very slow - decreasing the page's performance, because the rest of the JavaScript is first loaded on document ready, which its rarely reaches - because the browser locks up waiting for the file from Google.

I have tried to move the JavaScript file from the <head> tag to under my content. But the rest of the JavaScript is never fired because the browser waits for the file from Google.

Is there a way around this, or have anyone else experienced same problem? It began recently, and I have no idea why.

This is my code, if anyone is interested:

<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=true&amp;amp;key=ABQIAAAAa24xicak8_ghHX58i7La7hRFh9iM79SNC94rOejOtdMRvQmJiBS6Uv5F_1BNSh9ZuSzFXyekHISgew"&gt;    </script>
<script type="text/javascript" src="/js/maps.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    // Google Maps
    initialize();

    // Other JavaScript comes here....

   });
</script>

If I access

http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=true&amp;amp;key=ABQIAAAAa24xicak8_ghHX58i7La7hRFh9iM79SNC94rOejOtdMRvQmJiBS6Uv5F_1BNSh9ZuSzFXyekHISgew

The file loads instantly.

A: 

I have the same problem. I have to reload the page and eventually, it would load... not good enough...

tao
+1  A: 

On JavaScript optimization: always put your JS at the bottom of your even your Maps API script. I can't really think of any good reason to have any JS in the head.

Nael El Shawwa
+3  A: 

Use Google's Ajax APIs. From some time past, all of Google's services can be accessed through the JavaScript API. It's a modular system, you only have to include the JSAPI library, and then you can dynamically load the modules you need—it won't block your site.

<script type="text/javascript"        
        src="http://www.google.com/jsapi?key=ABCDEFG"&gt;&lt;/script&gt;
<script type="text/javascript">
google.load("maps", "2");
google.setOnLoadCallback(function() {
    // Your logic goes here.
    // It will be run right after the maps module was loaded.
});
</script>

For further details, see JSAPI's developer documentation.

Török Gábor
A: 

This is a rather old question now - the solution was to disable firebug (atleast for me).

meep