我正在尝试优化包含传单地图的网页的速度。根据 GTMetrix 和 Google PageSpeed Insight,我应该:
- 优化以下图像以减小它们的大小 [从' https://services.arcgisonline.com/ArcGIS/rest/services/ ...' 提供的几个图像],以下一代格式提供它们
- 延迟解析 JavaScript https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js
- 内联提供“leaflet.js”和“leaflet.css”
如果有任何类似的优化 Leaflet 地图的经验,我将不胜感激。是否值得为 Leaflet 内联提供 JS 和 CSS?我可以修改代码以其他更轻的格式调用“arcgisonline.com”图像吗?
我的简单网页的代码
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js'></script>
<div id='myMap' style='height:700px;width:700px;'></div>
<script>
var map = L.map('myMap').setView([51.505, -0.09], 13);
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {maxZoom: 19, attribution: 'Tiles © Esri — Source: Sources: Esri, DigitalGlobe'}).addTo(map);L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}', {maxZoom: 19}).addTo(map);
L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/{z}/{y}/{x}', {maxZoom: 19}).addTo(map); L.marker([51.505, -0.09]).addTo(map);
</script>
非常感谢。