cyberhobo / wordpress-geo-mashup

Official repository for Geo Mashup, the plugin that makes WordPress into a GeoCMS. Documentation:
https://github.com/cyberhobo/wordpress-geo-mashup/wiki/Getting-Started
63 stars 15 forks source link

Load Google maps API asynchronously #913

Open jbd7 opened 1 year ago

jbd7 commented 1 year ago

Hi there,

I'm observing an error in my console with my WP install, that seems to come only when GeoMashup is active on a page:

Loading the Google Maps JavaScript API without a callback is not supported: https://developers.google.com/maps/documentation/javascript/url-params#required_parameters

From the little I understand, what may be required is:

Documentation: https://developers.google.com/maps/documentation/javascript/url-params

I'm not sure if it comes from GeoMashup: I also see that the API call is made passing a $ver= parameter, with the WP version, that is not specified in the official documentation.

cyberhobo commented 1 year ago

I'm not able to reproduce this error. Could you link to a page where it occurs?

jbd7 commented 1 year ago

Apologies, it's a warning, not an error.

Example page I found, one currently live: https://bisogno.org/archivi/emilia-romagna/burocrazia-in-emilia-romagna/

Warning: image

Example from Google documentation: <script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> </script>

Where it may be potentially missing: https://github.com/cyberhobo/wordpress-geo-mashup/blob/72c5e6726090361ac1af6d1bdea6ffa544c208c0/render-map.php#L230

cyberhobo commented 1 year ago

That helps, thanks. It looks like synchronous loading is still supported but async is preferred.

WordPress script enqueuing doesn't support async loading, but it might be accomplished with another filter. The initialization callback will also have to be implemented and enqueued synchronously.