Skip Navigation

[Resolved] Deactivate conditionally Google Maps API where not needed

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 4 voices.

Last updated by leahk 6 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#604163

Hi Guys,

Toolset Maps is an absolutely wonderful plugin, however I noticed that it loads Google stuff also on pages where it is not needed.

I'm a bit confused, because according to this thread, the new version of Maps should only load Google API when needed:

https://toolset.com/forums/topic/google-maps-api-also-loads-on-pages-not-using-it/

But on my site and also on Toolset Reference site it also loads on a page where there are no maps:

hidden link

These two two things seem to be loaded everywhere:

hidden link

hidden link

It's only that on pages with maps, of course, much more is loaded from Google.

If I deactivate Autoptimize I see these two JS on pages without maps:

/wp-content/plugins/toolset-maps/resources/js/wpv_addon_maps.js
/wp-content/plugins/toolset-maps/resources/js/views_filter_distance_frontend.js

But these two Toolset JS are very small and their impact on load times is negligible, especially when concatenated with Autoptimize.

The Google scripts, on the contrary, sometimes are by far the slowest element on a page. But perhaps wpv_addon_maps.js is the one causing Google API to load?

According to GTmetrix, "googleapis.com/maps/api/js?libraries=place" is parsed during initial page load and blocks page rendering.

My site is optimized for speed, and generally I am quite satisfied with the results in speed tests, however these two Google scripts are often 'the offenders'. Sometimes they load OK, but sometimes they significantly affect page load times. Because they are not cacheable, they also affect negatively speed scores which can be shown to clients.

I only use maps on 2 custom post types and on 3 specific pages. Is there a way to conditionally dequeue (or whatever the correct term is) the maps API everywhere else with a function? Or perhaps some other method to deactivate them when not needed?

Best regards
Tom

By the way, the support forum has been acting strange for quite some time. It tells me that I opened some support tickets, but I haven't even participated in those threads... The count of my support threads seems wrong, too. EDIT: it seems that support threads attributed to me were started by forum moderators ?

#604173

Dear Thomas,

You are right, there isn't such a built-in feature within Toolset map plugin:
conditionally dequeue (or whatever the correct term is) the maps API everywhere else with a function

If you agree, we can take it as a feature request, our developers will evaluate it.

For the problem:
the support forum has been acting strange for quite some time

Where and how do you see the problem? please provide detail steps to see the problem, thanks

#604175
toolset.jpg

Dear Luo,

Yes, please kindly add selective deactivating of Google API as a feature request. In certain circumstances it affects page load speeds of Toolset sites. I believe everybody would benefit if it was possible to disable API calls to Google where not necessary.

As for the forum, above is a screenshot from my account. I know I didn't open those threads ? I've seen similar things in the past, must be some kind of a 'feature'. When I was opening this thread, I was informed that I had opened 3 tickets in the last 30 days. But I only opened 1 ticket during this period. It's not a big deal as long as my sites work and 'regular' tickets are answered ? Not a big deal at all ?

Kind regards
Tom

#604272

Thanks for the confirmation, I have forwarded it to our supporter Beda, he manages the feature request of Toolset Map plugin, our developers will evaluate it.

In the screenshot you mentioned above, there are two stick tickets:
https://toolset.com/forums/forum/professional-support/
And since they are not created by you, so they should not be counted.

#605622

Thank you very much, Luo.
Cheers
Tom

#605629

hi Thomas , Gonzales is something you can look into. cheers

Luo, pls update the status of my ticket, weekend is coming hope to clear that issue. please.

#918103

I came here searching for the same thing. We're trying to optimize speed and so it would be nice to not load that JS file on pages where it's not needed. If it's helpful to anyone, here's how I solved this:

It checks for a certain condition -- in my example whether the current post is a 'business or not' -- and if it's not a business, it removes the google-maps JS script.

function my_dequeue_script() {
if ( (get_post_type() != 'business') ) {
wp_deregister_script( 'google-maps' );
wp_dequeue_script( 'google-maps' );
}
}
add_action( 'wp_print_scripts', 'my_dequeue_script', 200 );