trying to optimize my map for some speed gains, I realized that although I don't use all the fancy user location detection stuff (using latest dev with the "Allow session storage" turned off), there are still two calls to google to download two files:

https://maps.googleapis.com/maps/api/js?sensor=true
https://maps.gstatic.com/maps-api-v3/api/js/20/4/main.js

That adds two unnecessary http-calls and at least 500ms to page loading, and whats worse is that sometimes the page waits up to two seconds for these files. As I'm using ip_geoloc with leaflet, I don't think I need those but I haven't found a way to turn them off. As maps are generally load-heavy stuff, I think it would be an easy gain for everybody to only load what is absolutely needed.

So, are these called from ip_geoloc, what are these for and can it only be loaded when needed? I tried to search for references to these files in ip_geoloc, geocoder, geofield and geophp, but haven't found any, so I actually have no clue where these are coming from.

I'm using this mapping stack, so maybe there is another culprit, just wanted to start my search somewhere:

geocoder
geofield
geophp
ip_geoloc
leaflet
leaflet_mapbox
leaflet_markercluster

Comments

RdeBoer’s picture

Good point heliogabal!

You may be on to something.

I have a suspicion that the first one may be due to IPGV&M (dev version), as a result of recent changes I've been trying out in that area.

The second one I'm less sure of.

I will investigate and get back to you.

Either way... while your site visitor may pay a price of 0.5s when first landing on your site, subsequent references to these files will not cause another delay as the browser will have cached these files, yeah?

Rik

RdeBoer’s picture

Assigned: Unassigned » RdeBoer

Fixed with latest checkin-in, 7.x-1.x-dev, becoming 7.x-1.27 when ready.

RdeBoer’s picture

Status: Active » Fixed
heliogabal’s picture

Hi Rik,
wow, you're really on fire - I would have expected a hint where to look closer, and you go ahead and refactor lots of stuff before I could even have a second look myself! I tried the new version today and the libraries are gone, and my site at least "feels" faster. Thanks again for your great work.

Of course you were right that it's only a cold cache penalty, but the first impression is important, and at least here in Germany, there's not a small number of people that get very sensitive with their data. So they might browse in incognito mode regularly without cache, and wouldn't be happy to let google know without neccessity which sites they visit. Plus, it was irritating while developing, and as far as I can tell by now, the site loads much more reliably now without any occasional delays.

So, much better to load only when needed...

RdeBoer’s picture

@heliogabal, #4
Thanks for the encouragement, much appreciated.

Yes, I believe I have the conditionals down as finely-grained as possible: only when the "Set my location" block is visible on the page being viewed AND it the block has the "Find me" button PLUS reverse-geocoding option on it, will the JS be loaded.
For technical reasons it is impossible to defer loading to the moment the "Find me" button is actually pressed, as this is a special form that starts an AJAX request. When trying it anyway, I got this error coming out of the Google code:

"Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened."

Rik

  • RdeBoer committed bf6aabd on 7.x-1.x
    Refinement of conditions when to load/not load Google JS [#2457183]
    
heliogabal’s picture

@Rik,
you're welcome, I wish I had more skills and time to help not only by pointing out the quirks I find... As for the defer solution, great to hear that it's as good as it technically can get. And if someone wants the functionality, they're going to have to load the necessary tools sooner or later, so to only load it if someone actually uses it on the site by clicking a button would be the icing on the cake, but I think everybody can live with it as is now.

Keep up the great work!
rainer

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.