Google Map API optimization

Questions and answers about change of functions, design, hosting etc.

Moderators: Koduc, Xpycm

Forum rules
Pay attention! Forum is not a means for guaranteed support of clients and users. An answer as well as a quick answer is not supposed on the forum. We post messages as soon as possible.

The message limit on the forum is 3 messages per day.
If you want to say "thank you" then use the function "Give good reputation point", which is a green icon "plus" under the nickname of the person, who answered the message.

Google Map API optimization

Postby luckyphan » 10 Oct 2018, 07:15

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
luckyphan
Stranger
 
Posts: 24
Joined: 30 Jul 2018, 09:09
Reputation point: 0

Re: Google Map API optimization

Postby Xpycm » 10 Oct 2018, 10:10

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;
    
//}
Dropbox
Open Real Estate CMS: FAQ | FAQ 2 | FAQ 3
Image
Xpycm
Web Developer
Web Developer
 
Posts: 281
Joined: 30 Dec 2011, 11:06
Reputation point: 2


Return to Questions and help for changes

Who is online

Users browsing this forum: No registered users and 10 guests

cron