问题描述
我想预压缩我的静态资产(不包括图片)并将其投放。
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/'));
我相信 express.compress()
会压缩快速运行,对于静态资产而言,这似乎对服务器CPU造成不必要的负担。
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?
推荐答案
一个href = https://www.npmjs.com/package/connect-gzip-static rel = nofollow> connect-gzip-static 模块似乎可以做到这一点。我尚未测试过。
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.
这篇关于快递:提供预压缩的静态资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!