Express: Serve pre-compressed static assets

你说的曾经没有我的故事 提交于 2019-12-12 12:07:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27756659/express-serve-pre-compressed-static-assets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!