From 5321cb4c46311f6645eabdfe7492e33a4fec0b38 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 19 Dec 2018 23:46:53 +0100 Subject: [PATCH] Enable gzip compression to reduce bandwidth consumption --- .../changelog.d/front-performance.enhancement | 51 +++++++++++++++++++ deploy/docker.proxy.template | 34 +++++++++++++ deploy/nginx.template | 35 +++++++++++++ docker/nginx/conf.dev | 33 ++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 changes/changelog.d/front-performance.enhancement diff --git a/changes/changelog.d/front-performance.enhancement b/changes/changelog.d/front-performance.enhancement new file mode 100644 index 000000000..03ca0e478 --- /dev/null +++ b/changes/changelog.d/front-performance.enhancement @@ -0,0 +1,51 @@ +Improved front-end performance by stripping unused dependencies, reducing bundle size +and enabling gzip compression + +Enable gzip compression [manual action suggested] +------------------------------------------------- + +Gzip compression will be enabled on new instances by default +and will reduce the amount of bandwidth consumed by your instance. + +If you with to benefit from gzip compression on your instance, +edit your reverse proxy virtualhost file (located at ``/etc/nginx/sites-available/funkwhale.conf``) and add the following snippet +in the server block, then reload your nginx server:: + + server { + # ... exiting configuration + + # compression settings + gzip on; + gzip_comp_level 5; + gzip_min_length 256; + gzip_proxied any; + gzip_vary on; + + gzip_types + application/atom+xml + application/javascript + application/json + application/ld+json + application/activity+json + application/manifest+json + application/rss+xml + application/vnd.geo+json + application/vnd.ms-fontobject + application/x-font-ttf + application/x-web-app-manifest+json + application/xhtml+xml + application/xml + font/opentype + image/bmp + image/svg+xml + image/x-icon + text/cache-manifest + text/css + text/plain + text/vcard + text/vnd.rim.location.xloc + text/vtt + text/x-component + text/x-cross-domain-policy; + # end of compression settings + } diff --git a/deploy/docker.proxy.template b/deploy/docker.proxy.template index 319f287e7..812027bfa 100644 --- a/deploy/docker.proxy.template +++ b/deploy/docker.proxy.template @@ -29,6 +29,40 @@ server { # HSTS add_header Strict-Transport-Security "max-age=31536000"; + # compression settings + gzip on; + gzip_comp_level 5; + gzip_min_length 256; + gzip_proxied any; + gzip_vary on; + + gzip_types + application/atom+xml + application/javascript + application/json + application/ld+json + application/activity+json + application/manifest+json + application/rss+xml + application/vnd.geo+json + application/vnd.ms-fontobject + application/x-font-ttf + application/x-web-app-manifest+json + application/xhtml+xml + application/xml + font/opentype + image/bmp + image/svg+xml + image/x-icon + text/cache-manifest + text/css + text/plain + text/vcard + text/vnd.rim.location.xloc + text/vtt + text/x-component + text/x-cross-domain-policy; + location / { include /etc/nginx/funkwhale_proxy.conf; proxy_pass http://fw/; diff --git a/deploy/nginx.template b/deploy/nginx.template index b81ecc61a..702dc05ee 100644 --- a/deploy/nginx.template +++ b/deploy/nginx.template @@ -43,6 +43,41 @@ server { root ${FUNKWHALE_FRONTEND_PATH}; + # compression settings + gzip on; + gzip_comp_level 5; + gzip_min_length 256; + gzip_proxied any; + gzip_vary on; + + gzip_types + application/atom+xml + application/javascript + application/json + application/ld+json + application/activity+json + application/manifest+json + application/rss+xml + application/vnd.geo+json + application/vnd.ms-fontobject + application/x-font-ttf + application/x-web-app-manifest+json + application/xhtml+xml + application/xml + font/opentype + image/bmp + image/svg+xml + image/x-icon + text/cache-manifest + text/css + text/plain + text/vcard + text/vnd.rim.location.xloc + text/vtt + text/x-component + text/x-cross-domain-policy; + + # end of compression settings location / { include /etc/nginx/funkwhale_proxy.conf; # this is needed if you have file import via upload enabled diff --git a/docker/nginx/conf.dev b/docker/nginx/conf.dev index 297cfa509..3e7a3515a 100644 --- a/docker/nginx/conf.dev +++ b/docker/nginx/conf.dev @@ -43,6 +43,39 @@ http { charset utf-8; client_max_body_size 30M; include /etc/nginx/funkwhale_proxy.conf; + # compression settings + gzip on; + gzip_comp_level 5; + gzip_min_length 256; + gzip_proxied any; + gzip_vary on; + + gzip_types + application/atom+xml + application/javascript + application/json + application/ld+json + application/activity+json + application/manifest+json + application/rss+xml + application/vnd.geo+json + application/vnd.ms-fontobject + application/x-font-ttf + application/x-web-app-manifest+json + application/xhtml+xml + application/xml + font/opentype + image/bmp + image/svg+xml + image/x-icon + text/cache-manifest + text/css + text/plain + text/vcard + text/vnd.rim.location.xloc + text/vtt + text/x-component + text/x-cross-domain-policy; location /front/ { proxy_pass http://funkwhale-front/front/;