4

I'd like to pre-compress my static assets (excluding images) and serve them.

To serve the public folder, I have:

app.use(express.static('path/to/public/'));

I believe express.compress() compresses on-the-fly, which seems like an unnecessary burden on the server CPU for static assets.

What's the canonical way to achieve this?

eye_mew
  • 8,855
  • 7
  • 30
  • 50
  • Bonus points for having it uncompress on the fly for clients that don't support compression, rather than requiring the uncompressed version to be kept on the server as well. – rjmunro Jan 27 '15 at 23:06

1 Answers1

3

The connect-gzip-static module seems to do this. I haven't tested it yet.

It doesn't support dynamically decompressing assets where the client doesn't support compression, which means you need to keep an uncompressed copy of the asset on the server as well, and you have to make sure they are in sync.

rjmunro
  • 27,203
  • 20
  • 110
  • 132