Problem/Motivation
Using a Google Maps map I get the following warning:
Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading
The module is using defer="defer" async="async" in the script tag to load the library, and it looks this is not good enough. Besides, I think we shouldn't be using both defer and async, it should be one or the other, in any case.
Steps to reproduce
Place a map from a Geolocation field.
Proposed resolution
Adjust the implementation to one of the approached suggested in https://goo.gle/js-api-loading.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3461359-warning-google-maps-5.patch | 2.19 KB | hemangi.gokhale |
Issue fork geolocation-3461359
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
christianadamski commentedv3 loads this stuff via core, so no async. v4 has this fixed through massive refactors.
Comment #3
hemangi.gokhaleUnfortunately, I'm getting this error using v4.
Comment #5
hemangi.gokhaleAdded the callback and
loading=asyncto GoogleGeocodingAPI.php so the geocoder uses the exact same Google Maps URL as the map.Updated GoogleGeocodingAPI.js to use
addMapProviderCallback("Google", …)instead of waiting on the addScript promise, matching the map's loading behavior.Now both components request the same Google Maps URL (allowing
addScriptto deduplicate) and wait for the same callback (DrupalGeolocationGoogleLoader). Attached is the patch from the MR.Comment #6
christianadamski commentedThanks!