react-google-places-autocomplete icon indicating copy to clipboard operation
react-google-places-autocomplete copied to clipboard

Google Maps JavaScript API has been loaded directly without loading=async

Open kaloraat opened this issue 2 years ago • 8 comments

I have been gettin this warning in console, anyone having the same issue?

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

Screenshot 2024-01-30 at 11 08 11 AM

kaloraat avatar Jan 30 '24 00:01 kaloraat

Add "loading=async" into your googlemap script tag.

This's solve for me.

SiRoCu1976 avatar Feb 10 '24 19:02 SiRoCu1976

How to achieve that but without using an API key, just by putting the iframe and PB parameter?
<iframe class="d-block h-100" src='https://www.google.com/maps/embed?pb=@mapValue' callback="Function.prototype" style="border: 0; min-height: 300px;" allowfullscreen="" loading="lazy" title="Map"></iframe>

JosueBCe avatar Mar 27 '24 14:03 JosueBCe

Here's the solution in razor pages and piranha cms, where the pb is taken from the share>"copy html" code in google maps If you're using another framework or language, just focus in the js

image

` @if (!string.IsNullOrEmpty(Model.Map)) {

<script>
    async function loadMap() {
        const mapValue = '@Html.Raw(Model.Map)';

        const iframe = document.createElement('iframe');
        iframe.classList.add('d-block', 'h-100');
        iframe.src = `https://www.google.com/maps/embed?pb=${mapValue}`;
        iframe.style.border = '0';
        iframe.allowFullscreen = true;
        iframe.loading = 'lazy';
        iframe.title = 'Map';

        document.getElementById('mapContainer').appendChild(iframe);
    }

    window.addEventListener('load', async () => {
        await loadMap();
    });
</script>

} `

JosueBCe avatar Mar 28 '24 16:03 JosueBCe

But what if we are using react-google-maps/api instead of script? Then what to do?

ashishFld avatar Apr 26 '24 04:04 ashishFld