Skip to content

Commit 484101e

Browse files
committed
Don't let map block
1 parent 0144dcf commit 484101e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

html/map.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% extends "base.html" %}
22
{% block extra_head %}
3-
<script src="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js"></script>
43
<link href="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.css" rel="stylesheet" />
54

65
<style>
@@ -177,7 +176,16 @@
177176
</div>
178177

179178
<script>
180-
maplibregl.accessToken = "pk.eyJ1IjoidHJpc2NodGFuZGVyIiwiYSI6ImNsNmZwNXY2MDAxOWEzZG41b213NWJ2ZjIifQ.pMjBga8kA5XQuDw19WQ8TQ";
179+
// Load MapLibre GL dynamically to prevent render blocking
180+
function loadMapLibrary() {
181+
const script = document.createElement('script');
182+
script.src = 'https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js';
183+
script.onload = initializeMap;
184+
document.head.appendChild(script);
185+
}
186+
187+
function initializeMap() {
188+
maplibregl.accessToken = "pk.eyJ1IjoidHJpc2NodGFuZGVyIiwiYSI6ImNsNmZwNXY2MDAxOWEzZG41b213NWJ2ZjIifQ.pMjBga8kA5XQuDw19WQ8TQ";
181189

182190
var map = new maplibregl.Map({
183191
container: "map",
@@ -433,5 +441,14 @@ <h3 class="name-popup">${properties.name}</h3>
433441
preload(...{{ thumbnails }});
434442
}
435443

444+
}
445+
446+
// Load map library after page loads to prevent blocking
447+
if (document.readyState === 'loading') {
448+
document.addEventListener('DOMContentLoaded', loadMapLibrary);
449+
} else {
450+
loadMapLibrary();
451+
}
452+
436453
</script>
437454
{% endblock %}

0 commit comments

Comments
 (0)