Vapor: Add support for GZIP

Created on 14 Nov 2016  路  4Comments  路  Source: vapor/vapor

Closed.

Most helpful comment

Compression is a good idea, but this needs some thinking about. Off the top of my head:

  • Header Accept-Encoding needs to be parsed to determine if the client supports compression (and if so, which one)
  • Ability to configure which content types should be compressed (makes sense for text-based stuff like XML, JSON, SVG etc.; not so much for JPEG or videos)
  • Compressed static content should be cached
  • Cached compressed static content should be recreated automatically if the original file is modified

If you need a short-term solution, use nginx as a reverse proxy and let it do the compression with configuration like this:

gzip             on;
gzip_proxied     any;
gzip_types       text/css text/plain text/xml application/xml application/javascript application/x-javascript text/javascript application/json text/x-json;
gzip_vary        on;
gzip_disable     "msie6";

All 4 comments

Compression is a good idea, but this needs some thinking about. Off the top of my head:

  • Header Accept-Encoding needs to be parsed to determine if the client supports compression (and if so, which one)
  • Ability to configure which content types should be compressed (makes sense for text-based stuff like XML, JSON, SVG etc.; not so much for JPEG or videos)
  • Compressed static content should be cached
  • Cached compressed static content should be recreated automatically if the original file is modified

If you need a short-term solution, use nginx as a reverse proxy and let it do the compression with configuration like this:

gzip             on;
gzip_proxied     any;
gzip_types       text/css text/plain text/xml application/xml application/javascript application/x-javascript text/javascript application/json text/x-json;
gzip_vary        on;
gzip_disable     "msie6";

compress text-based files to compile code

What do you mean by that? There's no such thing as compiled code for HTML, JavaScript, CSS, SVG etc.

However, integration with, for example, a LESS/SASS compiler or a JavaScript minifier could be considered.

@proyb6 There's no compilation happening in your example. If welcome.html contains the UTF8 string <h1>Hello, world!</h1>, the content returned is identical.

Compression would happen afterwards in both cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hjuraev picture hjuraev  路  3Comments

Joannis picture Joannis  路  4Comments

OlegKorchickiy picture OlegKorchickiy  路  3Comments

litan1106 picture litan1106  路  4Comments

nsleader picture nsleader  路  4Comments