我使用compress()中间件,将其放在configure()中的第一位.
I use compress() middleware, put it the first in configure().
app.configure('all', function(){ app.use(expresspress()); ... app.use(express.static('public'), { maxAge: oneMonth }); })如何检查我的内容是否已压缩?我有一个很奇怪的情况:1)在我的开发机器上:我需要localhost:4000/mystyle.css-看不到内容编码:gzip
How do I check that my content is gzipped? I've got a fricking strange situation: 1) On my dev machine: I reqeust localhost:4000/mystyle.css - DON'T see Content-encoding: gzip
2)当我将其部署到生产环境中时,如果我自己请求文件mydomain/mystyle.css-我在那里看到了内容编码:gzip
2) When I deploy it on production if I request the file it self mydomain/mystyle.css - I SEE there see Content-encoding: gzip
3)我请求mydomain,并在chrome开发工具中的网络"中查看,在那里找到mystyle.css,在那儿我看不到内容编码:gzip
3) I request mydomain and see in Network in chrome dev tools, find there mystyle.css and there I DON'T see Content-encoding: gzip
4)我使用不同的服务来检查我的内容是否被压缩,有人说是,有些则不是.
4) I use different services to check if my content is gzipped some says that it IS, some that it IS NOT.
WTF?有人可以解释吗?
WTF? Can some one explain?
推荐答案您的问题是您对app.configure的使用.不推荐使用此功能,但是您正在专门使用它,是为了寻找 all 环境.
Your issue is your use of app.configure. This is largely deprecated, but you're specifically using it such that you're looking for an all environment.
文档解释:此方法出于遗留原因而保留,实际上是一种如以下代码段所示的if语句."
The documentation explains: "This method remains for legacy reason, and is effectively an if statement as illustrated in the following snippets."
相反,只需使用app.use而不将它们包装在configure语句中.
Instead, just use the app.use without wrapping them in a configure statement.
更多推荐
Express.js:如何压缩资产
发布评论