Bugfix for serving .svgz (gzipped Scalable Vector Graphics) via connect.... #477

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

bf commented Feb 21, 2012

...static. Browsers with Webkit and Gecko rendering engines rely on the "Content-Encoding: gzip" HTTP header in order to properly recognize .svgz files.

This fixes a very annoying "feature" of at least Firefox and Chromium on Linux and Mac, as .SVGZ files are not recognized by the browser as gzipped .SVG files when served without the "Content-Encoding: gzip" HTTP header. As I'd love to serve scalable graphics to my users in a minified version - hence the svgz - this bugged us while serving content from static directories with node.js.

@bf bf Bugfix for serving .svgz (gzipped Scalable Vector Graphics) via conne…
…ct.static. Browsers with Webkit and Gecko rendering engines rely on the "Content-Encoding: Gzip" HTTP header in order to properly recognize .svgz files.
c7dc32c
Member
tj commented Feb 21, 2012

this doesn't really seem to be the right way to go about it. images are already compressed, not like you add a content-encoding for them, likewise when serving a tarball etc

bf commented Feb 22, 2012

I see your point, but it's not as easy as it seems. SVGZ images in particular are just not displayed in both latest Firefox and Chrom(e/ium) when the "Content-Type: gzip" header is missing.

Due to the nature of this problem, there is also a Firefox Bug which has been filed over a year ago regarding this very same issue. The opinion on this topic seems to be that .SVGZ (and .SVG.GZ) need to be served with the gzip header.

I think, that connect.static should prevent their users' from having to research the common case in which connect.static("/dir/") serves all files properly, but suddenly all svgz images are not working. This issue and its facets have been keeping me occupied for months now and I suppose a patch to static is the most user-friendly solution.

Member
tj commented Feb 22, 2012

I don't disagree I'm just arguing for the sake of better understanding the issue better from other perspectives. You could also likely add middleware before static(), check the pathname and add it there, so we're not cluttering up static() with a bunch of odd edge-cases

@Voronchuk Voronchuk referenced this pull request in balderdashy/sails Jan 28, 2014
Closed

Serving SVGZ static files #1350

just in case someone comes wandering off Google looking for how to do the middleware:

middleware: function (connect) {
            return [
            lrSnippet, // This is from connect-livereload
            pushState(), // This is from connect-pushstate
            function(req, res, next){ // This is our interesting function :)
              if(req.url.indexOf('svgz') != -1) 
                res.setHeader('Content-Encoding', 'gzip');
              next();
            },
            mountFolder(connect, '.tmp'), // This uses static inside.
            mountFolder(connect, 'app')
            ];
          }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment