[Feat] Implement Static fallback via the Maps Static API
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- frontend, performance, web-dev
Research direction
Start with src/components/map/index.tsx and the APIProvider context, then compare the prototype in the linked static-facade commit. Implement a StaticMap path using the documented center and zoom props, defer the regular map until user interaction, and provide UI indicating that interaction is required.
Written by the indexing model from the issue text.
Description
Target Use Case
Minimize the user experience impact of the library by improving paint time and responsiveness metrics.
Proposal
Data from HTTP Archive shows that Google Maps has the longest download times during page rendering when compared to the other most popular third-party libraries on the web:
| Median download time during page rendering for the top 10 most popular third parties (calculated using HTTP Archive and Lighthouse’s wastedMs attribute via the render blocking audit) |
| Query |
This happens because the Maps JavaScript API fetches ~240 kB of JavaScript across multiple scripts. In this library, we can circumvent this by delaying the instantiation of these scripts until the user engages with the map. While waiting for the user’s interaction, we can fetch and display an image via the Maps Static API passing in the same set of required props (center and zoom).
Optimized prototype of react-google-maps that displays an image and defers JS until user interaction) |
| Link |
To implement this feature, the <APIProvider> component of the library can keep track of whether the map has been selected as part of the context information it provides. We can use this to conditionally render either the “real” map versus a static version of it:
// src/components/map/index.tsx
import { StaticMap } from "./static-map";
// ...
return (
<div onClick={() => context.setMapSelected(true)}>
>
{context.mapSelected ? (
// Load normal map
) : (
<StaticMap {...props} /> // Load Static Map if map hasn't been clicked
)}
</div>
);
You can see all the changes in this prototype in this commit. Note that this is just a prototype, and the real implementation would offer some sort of UI that makes it clear that the map needs to be clicked in order to be interacted with.
Performance Tests
Comparing the current version of react-google-maps with the prototype above on the same site shows a significant difference in rendering times:
When the user interacts with the map, the same scripts are still fetched and executed. But by deferring them until they’re needed, the browser's main thread is freed up to handle other tasks while the document continues to load. This will improve both Largest Contentful Paint and Interaction to Next Paint.
The chart and table below present a comparison of these two metrics when applying this optimization to a representative Next.js website: https://news-site-next-static.netlify.app/.
| Largest Contentful Paint | Total Blocking Time* | |
|---|---|---|
| News Site Next | 3.38s | 0.25s |
News Site Next with react-google-maps |
7.12s (+3.74s) | 0.97s (+0.72s) |
News Site Next with react-google-maps (Optimized) |
4.22s (+0.84s) | 0.44s (+0.19s) |
Test conditions: WebPageTest - Emulated 4G Connection, Chrome, Moto G4 (Median Results - 3 Runs)
*Total Blocking Time is used as a lab proxy here for Interaction to Next Paint
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 195
- Avg merge
- 6h 26m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/react-google-maps
-
Polygon / Polyline: edits after a controlled `paths` update never reach `onPathsChanged`Possibly taken @anubhavlal07 claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
visgl/react-google-maps#1120 ·
Maintainers usually reply within 1 day
-
google maps issue
Difficulty 3/5 1-2 days Newbie friendliness 74/100
visgl/react-google-maps#1080 · 1 comment ·
Maintainers usually reply within 1 day
-
bug needs more info
Difficulty 3/5 1-2 days Newbie friendliness 45/100
visgl/react-google-maps#1039 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
visgl/react-google-maps#918 · 9 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
visgl/react-google-maps#905 ·
Maintainers usually reply within 1 day
All issues in visgl/react-google-maps
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day