Page 1 of 1

Google Map API optimization

PostPosted: 10 Oct 2018, 07:15
by luckyphan
Hi,

Seems that the map view loads extremely slow, with up to 5-10 seconds when the total of listings becoming larger. I've checked with google map support team & they said that I must config async & defer option to use the google map api.

The question is where should I put this async & defer for google map api option inside one of your javascript?

Thanks

Re: Google Map API optimization

PostPosted: 10 Oct 2018, 10:10
by Xpycm
Hello.

Try this solution.

In the protected\modules\apartments\components\CustomGMap.php file
instead of:
Code: Select all
self::$jsVars .= "\n loadScript('$js1', true);\n"

write:
Code: Select all
self::$jsVars .= "\n loadScript('$js1', true, true, true);\n"


And in the themes\YOUR_TEMPLATE_NAME\js\common.js
instead of:
Code: Select all
function loadScript(urlreload) {
    
reload reload || true;

    
//if(typeof scriptLoaded[url] == 'undefined' || reload){
    
var script document.createElement("script");
    
script.type "text/javascript";
    
script.src url;
    
document.body.appendChild(script);

    
scriptLoaded[url] = 1;
    
//}


write:
Code: Select all
function loadScript(urlreloadasyncdefer) {    
    
reload reload || true;
    
async async || false;
    
defer defer || false;

    
//if(typeof scriptLoaded[url] == 'undefined' || reload){
    
var script document.createElement("script");
    if (
async) {
        
script.async true;
    }
    if (
defer) {
        
script.defer true;
    }
    
script.type "text/javascript";
    
script.src url;
    
document.body.appendChild(script);

    
scriptLoaded[url] = 1;
    
//}