Lazy-load Google Maps without quota spikes
Loading the map only when someone wants it cuts billable map loads, makes the page faster and stops crawlers spending your quota. It takes one placeholder and a few lines of JavaScript.
How to tell this is your problem
- Map loads in Cloud Console are far higher than the number of people who actually look at the map.
- The map sits below the fold, in a footer or on every page, but it loads as soon as the page opens.
- Pages with a map are noticeably slower to become usable than pages without one.
- A low-traffic site gets quota warnings or OverQuotaMapError in the afternoon.
Why it happens
Google bills the Maps JavaScript API under its Dynamic Maps SKU, and the billable event is a successful map load. Most sites create the map as soon as the page loads, so every page view becomes a map load, whether or not the visitor scrolls to it. That includes:
- Visitors who leave before reaching the map.
- Crawlers and SEO tools that run JavaScript.
- Uptime monitors and link-preview services that render the page.
- Every page of the site, if the map is in a shared footer or sidebar.
The Maps loader also adds script downloads to the page, which costs performance on mobile even for visitors who never use the map.
The approach
Put a lightweight placeholder where the map will go. Create the real map only when the visitor clicks the placeholder, or when it scrolls into view. Pick the trigger that fits the page:
| Trigger | Best for | Effect on map loads |
|---|---|---|
| Click or tap | Contact pages, footers, store details | Lowest: only visitors who ask for the map |
| Scroll into view | Pages where the map is the main content | Lower: skips visitors who leave early |
| Page load | Full-screen map apps | Every page view, including bots |
Click-to-load gives the biggest saving. Most crawlers don't click, so they never create a map load.
The fix, step by step
- 01Give the map container a fixed height, so the placeholder and the map take the same space and the page doesn't jump. See fixing a zero-height container.
- 02Put a placeholder inside it: your address in text, a button labelled Show map, and optionally a background colour or a simple illustration.
- 03Include Google's inline bootstrap loader on the page. It defines google.maps.importLibrary, and the API itself is requested when you first call that function.
- 04Call importLibrary and create the map inside your click handler or IntersectionObserver callback, once.
- 05Remove any other script or plugin that also loads the API, so there is exactly one loader. See finding a duplicate loader.
- 06Keep one map per page. Google's cost guidance recommends reusing a single map and updating its viewport and markers.
<div id="map" class="map-box">
<button type="button" id="show-map">Show map</button>
<p>12 Example Street, London</p>
</div>
<script>
(g=>{/* Google's inline bootstrap loader, copied unchanged from the docs */})({
key: "YOUR_API_KEY",
v: "weekly",
});
let map;
async function loadMap() {
if (map) return;
const [{ Map }, { AdvancedMarkerElement }] = await Promise.all([
google.maps.importLibrary("maps"),
google.maps.importLibrary("marker"),
]);
const box = document.getElementById("map");
box.innerHTML = "";
const position = { lat: 51.5072, lng: -0.1276 };
map = new Map(box, { center: position, zoom: 15, mapId: "YOUR_MAP_ID" });
new AdvancedMarkerElement({ map, position });
}
// Click to load
document.getElementById("show-map").addEventListener("click", loadMap);
// Or load when scrolled into view:
// new IntersectionObserver((entries, obs) => {
// if (entries.some(e => e.isIntersecting)) { obs.disconnect(); loadMap(); }
// }, { rootMargin: "200px" }).observe(document.getElementById("map"));
</script>
The example requests both libraries in parallel with Promise.all(), as Google recommends, instead of awaiting them one after another. Advanced markers need a map ID; create one in Cloud Console or use the plain Marker class if you don't want one.
What to use as the placeholder
- Text and a button. Free and fast. Include the full address so visitors who never load the map still get the information.
- A link to Google Maps. A plain link to your listing opens the map in a new tab or the Maps app, and creates no API usage on your project.
- A Maps Static API image. Google suggests the Static API for thumbnails and maps with no interaction. Each image request is billed under its own SKU, so this reduces cost only if it replaces dynamic maps. Link the image URL directly from Google, and check Google's terms before storing any map imagery on your own server.
WordPress and page builders
Some maps plugins and page builders have a setting to load the map on click or to delay scripts until interaction. Performance plugins that delay JavaScript can also hold back the Maps loader. Test carefully: delaying only part of a plugin's code can stop the map loading at all. If your builder has no such option, replace its map widget with an HTML block containing the code above.
Confirm it is fixed
Open the page with the network tab filtered for maps.googleapis.com. Before you click or scroll, there should be no Maps requests. After you click, the loader and tiles should appear once. Check the console stays clean.
A scan loads the page without clicking, so after this change it will usually see no Maps requests on a click-to-load page. That is expected. Over the next week, watch map loads in Cloud Console fall towards the number of people who actually open the map.
Common questions
Does lazy loading a Google Map reduce costs?
Yes, if the map is only created when a visitor asks for it. Google bills successful map loads, so visitors and bots who never trigger the map don't add to the count.
Do crawlers really trigger Google Maps loads?
Crawlers that run JavaScript will create the map if your page does so on load. With click-to-load, most crawlers never click, so they don't create a map load.
Is it bad for SEO to lazy-load a map?
No. Search engines read your address from the page text, not from the map. Keep the address as text next to the placeholder.
Can I save a screenshot of my map as the placeholder?
Google's terms restrict storing map imagery, so check them before you do. Text, a plain button or a link to your Google Maps listing avoid the question entirely.
A scan tells you in about twelve seconds, from a clean session.