Express + GZip?

386 views
Skip to first unread message

Elias

unread,
Apr 16, 2011, 9:42:26 AM4/16/11
to Express
Hi,

as far as I know there is no option anymore for serving gzip-
compressed data via Express.

Are there any plans for re-implementing such a function?

Note: Grasshopper, an alternative to Express offers the compressed
serving of a static file, if a) the browser can read gzipped data and
b) the file is as a *.gz version on the server.


Elias

Johan Steenkamp

unread,
Apr 16, 2011, 4:00:03 PM4/16/11
to expre...@googlegroups.com
Here are some references about Express GZip (based on Connect GZip).

It was dropped as it was not efficient:

http://groups.google.com/group/express-js/browse_thread/thread/e4deba852baef654

http://groups.google.com/group/express-js/msg/27cfee95ce6e3721

Johan

> --
> You received this message because you are subscribed to the Google Groups "Express" group.
> To post to this group, send email to expre...@googlegroups.com.
> To unsubscribe from this group, send email to express-js+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/express-js?hl=en.
>
>

Elias

unread,
Apr 16, 2011, 5:33:16 PM4/16/11
to Express
Sure, I know these posts because I googled the problem first of all. I
am really surprised that there is no gzip implementation right now in
express. It's a fundamental utility for decreasing the size of your
application (think of sproutcore or cappuccino).

Why was the initial gzip implementation of connect considered as not
efficient?

Regards,

Elias

On Apr 16, 10:00 pm, Johan Steenkamp <jo...@orbital.co.nz> wrote:
> Here are some references about Express GZip (based on Connect GZip).
>
> It was dropped as it was not efficient:
>
> http://groups.google.com/group/express-js/browse_thread/thread/e4deba...

Jaime Bueza

unread,
Apr 16, 2011, 7:23:09 PM4/16/11
to expre...@googlegroups.com
Typically, If you're using nginx to front your node application, you can just have it gzip your static assets instead of relying on Express+Connect middleware to do it for you.

Hope that helps,
Jaime

Johan Steenkamp

unread,
Apr 18, 2011, 4:18:43 AM4/18/11
to expre...@googlegroups.com
I see GZip is on the roadmap for node-http-proxy:

http://blog.nodejitsu.com/updating-node-http-proxy

Johan

Nate Smith

unread,
Apr 23, 2011, 12:54:45 AM4/23/11
to expre...@googlegroups.com
I was similarly annoyed that this didn't exist, so I ripped out the implementation from Connect before it was removed and fixed it:

There is a drop in replacement for connect.static (aka express.static) that will gzip files before passing them off to connect.static for serving, and there is a simple piece of middleware that will compress any dynamic requests based on the Content-Type.

Let me know if you run into any bugs or performance issues.

- Nate

Nate Smith

unread,
Apr 23, 2011, 12:32:32 AM4/23/11
to Express
I also found it annoying that this didn't exist, so I ripped out the
old implementation from Connect and fixed it. I ended up having to re-
write a lot of it, but I think it is working pretty well now:
https://github.com/nateps/connect-gzip

There is a drop-in replacement for connect.static as well as a simple
piece of middleware to gzip any dynamic requests.

Let me know if you find any bugs or run into specific performance
issues.

- Nate

On Apr 18, 1:18 am, Johan Steenkamp <jo...@orbital.co.nz> wrote:
> I seeGZipis on the roadmap for node-http-proxy:
>
> http://blog.nodejitsu.com/updating-node-http-proxy
>
> Johan
>
>
>
>
>
>
>
> On Sun, Apr 17, 2011 at 11:23 AM, Jaime Bueza <jbu...@gmail.com> wrote:
> > Typically, If you're using nginx to front your node application, you can
> > just have itgzipyour static assets instead of relying on Express+Connect
> > middleware to do it for you.
> > Hope that helps,
> > Jaime
>
> > On Sat, Apr 16, 2011 at 2:33 PM, Elias <elias....@gmail.com> wrote:
>
> >> Sure, I know these posts because I googled the problem first of all. I
> >> am really surprised that there is nogzipimplementation right now in
> >> express. It's a fundamental utility for decreasing the size of your
> >> application (think of sproutcore or cappuccino).
>
> >> Why was the initialgzipimplementation of connect considered as not

Tom

unread,
Apr 23, 2011, 5:54:09 AM4/23/11
to expre...@googlegroups.com
That's great Nate, it should be added to the core module list in my opinion.

Thanks.

2011/4/23 Nate Smith <nps...@gmail.com>
--

vision media [ Tj Holowaychuk ]

unread,
Apr 23, 2011, 10:08:29 PM4/23/11
to expre...@googlegroups.com
gzip was insanely hacky and performed poor, so I removed it. poor gzip compression, is worse than no compression at all :p also depending on c++ addons is not something I want for connect core (not sure if you are using the one that exec()d or what)
--
Tj Holowaychuk
Vision Media
President & Creative Lead

Nate Smith

unread,
Apr 25, 2011, 3:07:40 AM4/25/11
to expre...@googlegroups.com
I took out the version that depended on the node-compress library to keep things simple. I don't think it is a good idea to have two parallel implementations of the same functionality.

I fixed some of the hackiness and rewrote the tests to be much more thorough. It is of course rather brittle to be relying on a command line utility like gzip, and it makes sense to me why you would want to keep this out of the connect core.

I think the performance tradeoff will depend heavily on how the module is used. At least in the static case, I think that gzipping text files clearly makes sense, and can be very significant for large script files.

Laurie Harper

unread,
Apr 25, 2011, 4:28:29 PM4/25/11
to expre...@googlegroups.com


The question is whether there is more overhead in spawning a child process, piping the data to it, piping the compressed result back to Node and serving the compressed data, vs. just serving the raw, uncompressed data directly. If your primary concern is performance and page load speed, rather than server bandwidth usage, some benchmarking is certainly warranted here...
--
Laurie Harper
http://laurie.holoweb.net/

Reply all
Reply to author
Forward
0 new messages