Skip to content

Instantly share code, notes, and snippets.

@AbelVM
AbelVM / tiles_refresh.js
Last active March 15, 2025 12:41
Refresh MapLibre layer' source when the tiles are older than a given TTL
window.__refresh__ = false; // global flag to check whether to refresh or not
const ttl = 1000 * 60 * 60; // tile time to live, ms
const map = new maplibregl.Map(
{
...,
transformRequest: (url, resourceType) => {
if (resourceType === 'Source' && url.indexOf('http://myHost') > -1) {
if(window.__refresh__){