Skip to content

feat: implement Leaflet.js offline map tile caching in service worker (#676)#684

Open
knoxiboy wants to merge 1 commit into
Shruti070107:mainfrom
knoxiboy:feat/issue-676-offline-map
Open

feat: implement Leaflet.js offline map tile caching in service worker (#676)#684
knoxiboy wants to merge 1 commit into
Shruti070107:mainfrom
knoxiboy:feat/issue-676-offline-map

Conversation

@knoxiboy

Copy link
Copy Markdown

Description

Resolves #676

This PR implements Leaflet.js map tile caching within the Service Worker fetch handler. Map tiles from tile.openstreetmap.org are intercepted and cached in a designated leaflet-tiles cache namespace. A cache size limit (1500 items, ~50MB) is enforced using a FIFO/LRU eviction policy. When the network is offline, the Service Worker falls back to served cached tiles, enabling riders to view optimized routes offline.

What changed

  • Added leaflet-tiles cache key and limitCacheSize helper to service-worker.js.
  • Excluded leaflet-tiles cache namespace from automatic cleanup during the service worker activation phase.
  • Added a fetch handler interceptor for tile.openstreetmap.org requests to implement network-first fallback-to-cache tile caching with LRU order updates.

Why

Offline map caching is essential for riders navigating transit routes with intermittent internet access. Without tile caching, network drops cause blank map tiles to render, disrupting operations.

How to test

  1. Launch the application and switch to the Active Route (Rider) view.
  2. Allow the map tiles to load.
  3. Switch Chrome DevTools network mode to Offline.
  4. Pan the map to verify that cached tiles continue to load perfectly.

Checklist

  • Tested changes locally
  • No lint/syntax errors introduced
  • Matches all issue criteria

Files Affected

  • service-worker.js

@knoxiboy knoxiboy force-pushed the feat/issue-676-offline-map branch from b9d2466 to 8a70df3 Compare June 13, 2026 11:17
@knoxiboy

Copy link
Copy Markdown
Author

@Shruti070107 Please review this pr and merge it

1 similar comment
@knoxiboy

Copy link
Copy Markdown
Author

@Shruti070107 Please review this pr and merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Implement Leaflet.js Offline Map Tile Caching

1 participant