Since this module was installed, every page loads something from maps.google.com whether the page has a map or not. That server is sometimes slow to respond, so it slows my site down. Is there a way to avoid loading this on every page?

Comments

toddcortez’s picture

Title: Why load google maps on every page? » Seeing the same here. Pretty much a show-stopper.

The module is unusable like this.

webgeer’s picture

Title: Seeing the same here. Pretty much a show-stopper. » Google Map script loads on every page
Assigned: Unassigned » webgeer
Category: bug » feature

Currently whenever you load a page if this module is refers to a piece of script on the google website to initiate google maps. This is supposed to be in the header.

Unfortunately this is not a simple fix. As far as I can tell there is no way to have content put into the header only when a certain filter is used. The filter only runs once and from then on it uses a filtered version of the page. Therefore the only way you could dynamically decide whether to send the header or not is to scan through each node before it is displayed looking for google map code. I don't like the idea of doing that. This also would not allow you to use the gmaps.module API for other uses, which is one of the reasons I wrote this module.

I will investigate having javascript only include the code dynamically, but I don't have a lot of confidence that this will work. (I don't think browsers will dynamically include offsite scripts for security reasons -- but I haven't checked this yet.)

Another potential option could be to try and move this code into the node potion of the page, but as a minimum this would mean loading the external script on every instance of a node with a map on it on the page, and I think will introduce some other problems as well.

The only reason this is a problem is that there have been a few days this last couple of weeks where the maps.google.com website has been very slow to respond. I hope this is just a temporary issue and that it will soon be resolved.

I have changed this from a bug report to a feature request as it currently works as designed, it is just that admittadly the design is not optimal.

toddcortez’s picture

One possible solution to this is to have an option to invoke the map API code inside an iframe. I've been experimenting a bit with this directly using the Google API.

T

webgeer’s picture

Thanks for the suggestion, but on looking at how iframes work, think that would be quite complicated and would have other problems for some things I would like to be able to do.

I do plan on addressing this issue by giving the users the option of whether they want to run the filters dynamically and only load the google initialization script on pages with gmap filters. (But take a performance hit by loosing cache on all nodes that have the gmap filter run) or to do it as currently where it uses cached nodes but it runs the google map initialization script on every page.

I have to say other than a few days last week the delay contacting the google script has not been noticeable. I really think this was a short lived problem.

jivyb’s picture

What about this Dhtml AJAX script that puts content directly into a div without an iframe...http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

I don't really know much about this, but it sounds like a good way to get around iframes

jferjan’s picture

Here is a temporary solution. I hope somebody finds this information helpfull.

  1. set Google map method to "None".
  2. enable gmap filter in admin/filters for php input fotmat
  3. add this code to the node containing gmap macro. Replace key with your own key and use php input format.
    <?php
    drupal_set_html_head('<script type="text/javascript" src="/drm/modules/gmap/gmap.js"></script>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.55a&amp;key=ABQIAAAAuz4gYG7X0IRVKc_VAIERDRTanIaqEfFX3V6jK4SriDQWZchkpBSR60fqipDKsWUHIS-tHZj9TP83TA" type="text/javascript"></script>');
    ?>
marcoBauli’s picture

tryed setting Google map method to "None": my homepage loads 1-2 seconds faster. On a 4-5 seconds average means 35% faster!

jferjan's trick is good (personally tryed it in my map-enabled nodes' templates and works nice), but is for sites that make very limited use of Google maps.
API should infact be loaded on all location-enabled pages: nodes submission forms, users and nodes pages (/map/users, /map/nodes).

Would it be possible to use opposite approach and "exclude" the Gmap header on some pages/content-types instead (frontpage, profiles, contact forms, ....)?

geodaniel’s picture

Version: 4.6.x-1.x-dev » 4.7.x-1.x-dev

It's my understanding that the 'dynamic' option should stop the code loading in all pages except those that have maps. Having said that, I've seen the script being added to pages that don't have maps (though not all the time, it's inconsistent).

(I presume the recent comments are against the 4.7 version?)

bdragon’s picture

Here's what's happening:

Drupal's filter system caches the "no cache" state of the filter! GMap's filter hook returns either TRUE or FALSE as the "no cache" state depending on the gmap method, and whatever it was at when the system integrates the filter is what it's stuck with.

I suppose adding code to twiddle the cache column in the filter_formats table and then truncating the page cache when switching methods would be more reliable.

doclalor’s picture

jferjan #6 - Worked great, thanks!

bdragon’s picture

Status: Active » Closed (fixed)