Zipping a HTTP Response? Possible?
Having an issue where certain page's contents are abnormally huge. In the 5 to 10 megs range.
This is rendered using Velocity and Java on the server side开发者_运维知识库. It's obviously possible to compress/zip this response but what's a reasonable way to handle the unzipping on the browser/client side?
It's built-in to most modern browsers. As long as the response is some kind of text or something easily compressible then your request/response just have to have to correct headers.
Request
Accept-Encoding: gzip,deflate
Response
Content-Encoding: gzip
If the Accept-Encoding header of the request doesn't include gzip you shouldn't zip it obviously because the client/browser can't handle it.
In general you should gzip any text content as long as it makes sense to do so. If the resource is 500 bytes instead of 500kbytes it might not make sense for performance reasons. Some examples are html, xml, json, javascript and you can configure your server, which types of files to compress and what the size limit should be.
Enabling Gzip
- Tomcat
- IIS
- Glassfish
精彩评论