npx skills add ...
npx skills add mapbox/mapbox-agent-skills --skill mapbox-web-performance-patterns
Performance optimization patterns for Mapbox GL JS web applications. Covers initialization waterfalls, bundle size, rendering performance, memory management, and web optimization. Prioritized by impact on user experience.
npx skills add mapbox/mapbox-agent-skills --skill mapbox-web-performance-patterns
This skill provides performance optimization guidance for building fast, efficient Mapbox applications. Patterns are prioritized by impact on user experience, starting with the most critical improvements.
Performance philosophy: These aren't micro-optimizations. They show up as waiting time, jank, and repeat costs that hit every user session.
Performance issues are prioritized by their impact on user experience:
Problem: Sequential loading creates cascading delays where each resource waits for the previous one.
Note: Modern bundlers (Vite, Webpack, etc.) and ESM dynamic imports automatically handle code splitting and library loading. The primary waterfall to eliminate is data loading - fetching map data sequentially instead of in parallel with map initialization.
Timeline: Map init (0.5s) → Data fetch (1s) = 1.5s total
Timeline: Max(map init, data fetch) = ~1s total
If you know the exact area users will see first, setting center and zoom upfront avoids the map starting at a default view and then panning/zooming to the target, which wastes tile fetches.
Impact: Significant reduction in time-to-interactive, especially when deferring terrain and 3D layers
Problem: Large bundles delay time-to-interactive on slow networks.
Note: Modern bundlers (Vite, Webpack, etc.) automatically handle code splitting for framework-based applications. The guidance below is most relevant for optimizing what gets bundled and when.
Impact: Reduces initial bundle by 30-50% when moving from inlined to hosted styles
Problem: Too many markers causes slow rendering and interaction lag.
Result: 5,000 DOM elements, slow interactions, high memory
Performance: 10,000 features render in <100ms
Impact: 50,000 markers at 60 FPS with smooth interaction
When building a Mapbox application, verify these optimizations in order:
moveend)map.on('error', …) (or visible error UI) so style/tile/token failures are not silentFirst-pass agent code often ships a map with no map.on('error'), no map.remove(), and a tiny point set that never exercises cluster: true. Production demos need error visibility, teardown, and realistic scale.
Target metrics:
For detailed patterns on specific topics, load the corresponding reference file:
references/data-loading.md — GeoJSON vs Vector Tiles decision matrix, viewport-based loading, progressive loading, vector tiles for large datasetsreferences/interactions.md — Debounce/throttle events, optimize feature queries, batch DOM updatesreferences/memory.md — Map cleanup patterns, popup/marker reuse, feature state vs dynamic layersreferences/mobile.md — Device detection, mobile-optimized layers, touch interaction, constructor optionsreferences/layers-styles.md — Consolidate layers with data-driven styling, simplify expressions, zoom-based visibility