Mapshot

by palats

Generates a zoomable render of the whole map.

Utilities
2 days ago
1.0 - 1.1
3.52K

i Caching static content

3 years ago
(updated 3 years ago)

To be able to serve the static content through providers that cache files to minimize bandwidth. All request needs to be unique to the file and change when the file changes.

An example of an easy way to do this is to add a garbage query parameter with garbage data, like the md5 checksum of the file. Or a timestamp of when the files where generated stored in the json file. Making the url unique for every file when it changes.

/zoom_0/tile_0_0.jpg?static=<checksum>

I have no knowledge with leaflet so I don't know if this is possible.

3 years ago

That sounds doable, but I would need to dig a bit more into it. Leaflet needs predictable URLs, but that does not prevent to have some prefix/suffix - i.e., using an ID unique per render instead of per file. That loses potential caching across renders, but I don't expect any caching across renders anyway.

The challenge though will be to keep pretty URLs for simple cases. In your use case - do you care about caching everything, or only large images/tiles? (do you have a specific provider you are targeting?)

3 years ago

Yeah, adding a ?v=<unix timestamp> to each jpg request and update that timestamp on new renders would work fine. This would allow me to tell the cache system to save stuff for e.g. 7 days and still be able to update to a new render and replace tile files, making it retrieve new tile files from the origin server during those 7 days.

I'm personally targeting cloudflare with their standard cache level. Cache everything. Many small files becomes a lot of bandwidth pretty fast with a couple of visitors.

https://support.cloudflare.com/hc/en-us/articles/200168256-Understand-Cloudflare-Caching-Level

Cheers

3 years ago

I've changed the layout of the generated data, it should be a lot more cache friendly in practice. The approach I've taken is to generate a unique directory name for each mapshot - as all files are changing usually anyway. The javascript is in its own file, with a hash of the content in the name. The entry point (i.e., HTML) is less cacheable (it cannot have a unique name), but in practice, it should be fairly minor. The README (https://github.com/Palats/mapshot#caching) should have a bit more details.

Fwiw, I've moved the example to https://mapshot.palats.xyz , which uses Cloudflare+Backblaze (+my own server for html files) with extensive caching - and it seems to work quite decently.

New response