问题
I was trying to understand more on Transfer-Encoding:chunked
. referred some articles:
http://zoompf.com/blog/2012/05/too-chunky and "Transfer-Encoding: chunked" header in PHP.
I still didn't get very clear picture. I understand setting this encoding allows server to set content in chunk to the browser and cause partial rendering of content at a time that makes web site responsive.
If I've a web application that serves dynamic content (ex: JSF based web app) hosted on IBM WAS, most of the web pages are designed to server rich static content with lots of CSS and JS files + dynamic content. How can I set transfer-encoding 'chunked' for my pages? Or in other words:
- How do you decide which page will have
'Transfer-Encoding: chunked'
and how do you set it for that page?
Your personal experience will certainly be valuable for my understanding.
回答1:
Transfer-Encoding: chunked
isn't needed for progressive rendering. However, it is needed when the total content length is unknown before the first bytes are sent.
回答2:
When the server needs to send large amount of data, chunked encoding is used by the server because it did not exactly know how big (length) the data is going to be. In HTTP terms, when server sends response Content-Length header is omitted by the server. Instead server writes the length of current chunk in hexadecimal format followed by \r\n and then chunk, followed by \r\n (Content begins with chunk size in hex followed by chunk)
This feature can be used for progressive rendering; however the server needs to flush the data as much as possible so that client can render content progressively (in case of html,css etc)
This feature is often used when server pushes data to the client in large amounts - usually in large size (mega/giga)
Mozilla Documentation
来源:https://stackoverflow.com/questions/19907628/transfer-encoding-chunked