CDNs and Local Fallbacks for Leaflet and Plugins

76 views
Skip to first unread message

core...@umich.edu

unread,
Aug 2, 2018, 4:16:24 PM8/2/18
to Leaflet
Hello all,

I'm working on a leaflet map that displays bird's-eye views of American cities on a map of the US. I'm referencing the CDNs for leaflet 1.3.3 and some of the plugins I'm adding to my map. I'm concerned, though, that in case some of the plugins go down or the CDNs cannot be accessed, that the map will also go down.

My question is, how do I create a fallback for my CDNs in case of failure? If any of you know, I'd love an example to go with it, that way I can precisely mimic the language necessary. I'll leave a snippet of my code down below so feel free to reference it. Thanks!

  <!-- Leaflet -->
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.3/leaflet.css" media="screen, print" rel="stylesheet" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
 
crossorigin="">
 
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.3/leaflet.js' integrity="sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q=="
 
crossorigin=""></script>


 
<!-- MarkerCluster Plugin -->
 
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.3.0/MarkerCluster.css" />
 
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.3.0/MarkerCluster.Default.css" />
 
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.3.0/leaflet.markercluster.js'></script>


 
<!-- tagFilterButton Plugin -->
 
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-tag-...@0.0.4/src/leaflet-tag-filter-button.css">
 
<script src="https://cdn.jsdelivr.net/npm/leaflet-tag-...@0.0.4/src/leaflet-tag-filter-button.js"></script>

Pouemes

unread,
Sep 3, 2018, 4:09:37 AM9/3/18
to Leaflet
this seems to work
 <script>!window.leaflet && document.write(unescape('%3Clink rel="stylesheet" href="leaflet.css"%3E'))</script>
<script>!window.leaflet && document.write(unescape('%3Cscript src="leaflet.js"%3E%3C/script%3E'))</script>

if you know hox to do do the same for the basemap source, i shall be happy
Reply all
Reply to author
Forward
0 new messages