开发者

Need recommendation for Node.js Gzip static resource

开发者 https://www.devze.com 2023-03-15 15:55 出处:网络
so, is connect\'s gzippo good? I have two questions, 1) if i want to serve static javascript ( i use express), I can just do gzippo and do that:

so, is connect's gzippo good?

I have two questions,

1) if i want to serve static javascript ( i use express), I can just do gzippo and do that:

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

is that right? what if the client browser doesn't support gzip (in rare case)? will it automatically send the uncompress version? also, will the zipped file cached? or compress for every request?

2) If the app's get method returns JSON, what is the correct method to handle compress result? should I first check the http.req开发者_如何转开发uest header's "accept-encoding" and make sure it support gzip, then compress the JSON result? or gzippo will automatically handle it?


one more question: 3) If I have a uncompressed JS file (e.g. my.js) and a manually gzipped JS file (e.g. my.js.gzip) in the public folder, which one will be served if client side script include is

do I have to specify as ?

that a question not just on node.js but also on normal apache server. :) thanks.


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

According to this line:

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

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

It will send uncompressed file.

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.

I read this in comment so I assume right now it stores gzipped file in memory. But even more important it also uses client side caching.

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?

I think you stand correct. I don't believe Gzippo will handle other routes, but only static folder.


Some other tips:

  • You should combine all your js/css when deploying => http://developer.yahoo.com/performance/rules.html#num_http. I don't believe gzippo does this already.
  • You should consider a CDN for better performance.


Consider using some cloud API middleware like AWS APIGateway, some CDNs supporting GZipping and you always can craft your own reverse proxy server with nginx or HAproxy. See bullet 3 here: http://goldbergyoni.com/checklist-best-practice-of-node-js-in-production/

0

精彩评论

暂无评论...
验证码 换一张
取 消