From a95a9768135bcaaa856a7cca98409a49250c96fa Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 3 Dec 2022 23:30:31 +0100 Subject: serve gzip compressed GPX data if possible This way, we not only save the decompression time, we can also save bandwidth! We *might* even consider using brotli, which seems to be widely supported and has even better compression ratios, but brotli compression of full efficiency is also slow. Ideally, we'd save a "fast compressed" version of the GPX file on upload, and then have a slower background-queue re-compress them with higher settings. That however should probably wait till we move the GPX data out of the database(?!), then we can even serve the data straight with a FileResponse. --- fietsboek/views/detail.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 38dc31f..a135916 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -59,7 +59,13 @@ def gpx(request): :rtype: pyramid.response.Response """ track = request.context - response = Response(track.gpx_data, content_type="application/gpx+xml") + # We can be nice to the client if they support it, and deliver the gzipped + # data straight. This saves decompression time on the server and saves a + # lot of bandwidth. + if 'gzip' in request.accept_encoding: + response = Response(track.gpx, content_type="application/gpx+xml", content_encoding="gzip") + else: + response = Response(track.gpx_data, content_type="application/gpx+xml") response.md5_etag() return response -- cgit v1.2.3