Express.js:如何压缩资产

编程入门 行业动态 更新时间:2024-10-23 19:24:12
本文介绍了Express.js:如何压缩资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用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:如何压缩资产

本文发布于:2023-10-12 16:51:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资产   Express   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!