Support

Account

Home Forums General Issues Solution needed for slow Google Maps loading. Reply To: Solution needed for slow Google Maps loading.

  • I don’t have a specific solution for you, but what you need to do is to load the script and then do the map initialization

    
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
    <scirpt>
       ... code here
    

    This means that you need to create a function that runs when the page loads that does all of this, first inserting the google maps api script into the header and then doing the initialization.

    
    (function($){
       // insert https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY into document <head>
       // initialize maps
    }(jQuery);
    

    Google is really good at destroying your page speed, aren’t then? Anyway, I do not think that this will improve your page load time. The main issue is that the script is still running automatically. I realize this has nothing to do with ACF but having gone through a similar excercise with youtube videos it is important to not. The only real way to improve page speed is that there is some other condition for loading the script other then when the page is loaded, for example with an onclick or in mycase I did the intialization on mouse over so the some specific action is needed. You could also potentially use a timeout. In order to improve page performance there needs to be a significant break (idle) in script execution so that the tools for testing performance detect that the page is loaded.