Open jameshadfield opened 5 years ago
Hello!
In #826 I bundled all external CSS and fonts, so that they could be served statically from localhost. It seems that the only remaining remote resource is mapbox.
In #827 I added server-side map tile cache, which allows running the application offline.
Currently auspice can run “locally” such that datasets are sourced from the user’s computer. This is fantastic, but requires an internet connection to load a number of cross-origin resources (see below). This includes mapbox tiles, meaning the map isn’t usable when offline. This functionality would be particularly desirable for conference talks etc where network connections are often unavailable, as well as developing / running auspice while offline.
Here are the cross-origin requests made by auspice. These should be either made available offline — where allowed — or auspice should gracefully handle their non availability. (It may be that, when an internet connection is available, some are preferable to load from other domains for performance reasons, or as specific requests that can be cached.)
Fonts / styles
index.html
. Available in a HTTP cache for 24 hours.~ Update: fixed in #826index.html
& HTTP cached for up to 1 year.~ Update: fixed in #826index.html
HTTP cached for up to 1 year.~ Update: fixed in #826The number of font files — typically
font/woff2
files — requested varies according to which ones (and weights) are used in the current page. All seem to have cache limits of 1 year. They’re requested fromfont-awseome.min.css
, the lato fonts description, and a bundled leaflet script. Number of requests varies from 2 (auspice splash page) to 15 (zika).Scripts
Mapbox tiles
Mapbox requests a number of
png
map tiles (16 for zika before zooming/panning), all cached for up to 12 hours. Storing the files in the git repo isn’t allowed, but this thread provides a solution using service workers and one usingCacheStorage
(which is a service worker API but is apparently also available in window scope).UPDATE: see #827 for a possible implementation of tiles
Service workers: the solution?
At a glance, service workers are my preferred solution as we could use them for other things as well (but
CacheStorage
might be simpler).Service workers would allow us to use fonts offline as well (implementation here). On whether this is strictly allowed, this thread — from the Google Chrome GitHub org — is the best resource I’ve found, stating:
Eventually, service workers could allow nextstrain.org to work without an internet connection, but that’s quite far away ;)