Hi Botble
At PostForm.php I have add a script code
Assets::addScriptsDirectly('https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places', 'header');
Assets::addScriptsDirectly('vendor/core/plugins/blog/js/post.js');
At post.js I call new google.maps.LatLngBounds()
via console.log
But I get 1 warning:
js?key=AIzaSyAb1vGO9…places?v=2.53.6:236 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
And 1 error:
post.js?v=2.53.6:14 Uncaught
TypeError: Cannot read properties of undefined (reading 'Autocomplete')
at initAutocomplete (post.js?v=2.53.6:14:47)
With the warning, I understand that the google sdk file is not being loaded properly, so how can I add the async and defer tag to Assets::addScriptsDirectly ?
How can I add async defer like the following example?
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places?v=2.53.6" async defer></script>