Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Google maps API asynchronously #913

Open
jbd7 opened this issue Feb 11, 2023 · 3 comments
Open

Load Google maps API asynchronously #913

jbd7 opened this issue Feb 11, 2023 · 3 comments

Comments

@jbd7
Copy link

jbd7 commented Feb 11, 2023

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:

  • add a callback parameter when loading the Google Maps API
  • (optional) update the API URL from //maps.google.com/maps/api/js to //maps.googleapis.com/maps/api/js

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.

@jbd7 jbd7 changed the title Calls to Google Maps API throws an error Calls to Google Maps API throw an error Feb 11, 2023
@cyberhobo
Copy link
Owner

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

@jbd7
Copy link
Author

jbd7 commented Mar 19, 2023

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:

} else if ( 'googlev3' == $map_data['map_api'] ) {

@cyberhobo cyberhobo changed the title Calls to Google Maps API throw an error Load Google maps API asynchronously Mar 19, 2023
@cyberhobo
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants