Mapbox GL JS token rotation handling after deployment: cache inconsistency
0 reputation · 14 Jan 2023, 07:30 UTC
When deploying a Mapbox GL JS application, developers often rotate access tokens to limit exposure or comply with security policies. The goal is to allow the map to continue loading tiles after a token change without forcing users to reload the entire page.
However, the interaction between token rotation and browser caching layers—such as the HTTP cache, service‑worker cache, and Mapbox GL JS internal tile cache—is not consistently defined across browsers, leading to situations where stale tokens are still used and requests fail with 401 errors until a hard refresh occurs.
What approaches can reliably invalidate cached map tiles when a token is rotated? How do major browsers treat stale tokens in their service‑worker versus HTTP caches? Does Mapbox GL JS provide a setting to force token refresh on each tile request?