eye_mew
eye_mew

Reputation: 9133

Express: Serve pre-compressed static assets

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?

Upvotes: 4

Views: 1976

Answers (1)

rjmunro
rjmunro

Reputation: 28076

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.

Upvotes: 3

Related Questions