javascript - 需要推荐 Node.js Gzip 静态资源

标签 javascript node.js gzip compression static-content

那么connect的gzippo好用吗?

我有两个问题,

1) 如果我想提供静态 javascript(我使用 express),我可以只做 gzippo 并这样做:

app.use(gzippo.staticGzip(__dirname + '/public'));

是吗?如果客户端浏览器不支持 gzip(在极少数情况下)怎么办?它会自动发送解压缩版本吗?另外,压缩文件会被缓存吗?还是针对每个请求进行压缩?

2) 如果应用程序的 get 方法返回 JSON,处理压缩结果的正确方法是什么?我应该先检查 http.request header 的“accept-encoding”并确保它支持 gzip,然后压缩 JSON 结果吗?或者 gzippo 会自动处理它?


还有一个问题: 3)如果我在公用文件夹中有一个未压缩的 JS 文件(例如 my.js)和一个手动压缩的 JS 文件(例如 my.js.gzip),如果客户端脚本包含

我必须指定为吗?

这不仅是关于 node.js 的问题,也是关于普通 apache 服务器的问题。 :) 谢谢。

最佳答案

what if the client browser doesn't support gzip (in rare case)? will it automatically send the uncompress version?

根据这一行:

https://github.com/tomgallacher/gzippo/blob/master/lib/staticGzip.js#L121 :

if (!~acceptEncoding.indexOf('gzip')) {
            return pass(filename);
        }

它将发送未压缩的文件。

also, will the zipped file cached? or compress for every request?

//This is storing in memory for the moment, need to think what the best way to do this.

我在评论中读到这个,所以我假设它现在将 gzip 文件存储在内存中。但更重要的是,它还使用客户端缓存。

If the app's get method returns JSON, what is the correct method to handle compress result? should I first check the http.request header's "accept-encoding" and make sure it support gzip, then compress the JSON result? or gzippo will automatically handle it?

我认为你的观点是正确的。我不相信 Gzippo 会处理其他路由,但只会处理静态文件夹。


一些其他提示:

关于javascript - 需要推荐 Node.js Gzip 静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481151/

相关文章:

node.js - 使用 async/await 逐一读取文件

node.js - 尽管安装了npm,但Gatsby找不到fs

javascript - 为什么 gzip 后的 html 文件显示时没有 JS 和 CSS?

javascript - Jquery 中的自定义验证

javascript - 在 CasperJS/PhantomJS 中捕获由 evaluate() 引起的错误?

javascript - 仅发布缩小版本的 JavaScript 文件 (ASPNET Core)

node.js - 无法在设备上安装应用程序,react-native

c# - Global.asax 上的 ASP.NET gzip 脚本和 CSS

linux - 即时解压缩和压缩为另一种格式

javascript - FFMPEG 调整视频大小在浏览器或 IOS 中不起作用