backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

Ensure SVGZ is served with correct encoding #6647

Open klonos opened 3 months ago

klonos commented 3 months ago

This is the same as https://www.drupal.org/project/drupal/issues/2092245 (slated for backporting to D7).

https://en.wikipedia.org/wiki/Scalable_Vector_Graphics#Compression

SVG images, being XML, contain many repeated fragments of text, so they are well suited for lossless data compression algorithms. When an SVG image has been compressed with the industry standard gzip algorithm, it is referred to as an "SVGZ" image and uses the corresponding .svgz filename extension. Conforming SVG 1.1 viewers will display compressed images.[8] An SVGZ file is typically 20 to 50 percent of the original size.[9] W3C provides SVGZ files to test for conformance.[10]

Every web browser that supports SVG supports SVGZ as it is just a standard gzip HTTP encoding.

Having this in core means that every contrib developer can have confidence that SVGZ will work.

Problem/Motivation

Drupal is not serving SVGZ files with the correct encoding.

Proposed resolution

All that is required is for these two lines to be added to .htaccess as described here: http://kaioa.com/node/45

AddType image/svg+xml svg svgz
AddEncoding gzip svgz

nginx can also be configured to serve SVGZ correctly. At my request, Pantheon have already updated their nginx configuration to support it and I have confirmed that it works.

I have also modified web.config for IIS as described here: http://forums.iis.net/t/1175276.aspx and confirmed that it works.

klonos commented 3 months ago

PR: https://github.com/backdrop/backdrop/pull/4824

I had to adapt the test slightly, as it was failing on my local because Content-Encoding was not set, whereas Content-Type was (I suspect that X-Content-Type-Options nosniff has something to do with that, but it's there for good reasons).