那么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 会处理其他路由,但只会处理静态文件夹。
一些其他提示:
- 你应该在部署时结合所有的 js/css => http://developer.yahoo.com/performance/rules.html#num_http .我不相信 gzippo 已经这样做了。
- 您应该考虑使用 CDN 以获得更好的性能。
关于javascript - 需要推荐 Node.js Gzip 静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481151/