Transfer-Encoding: chunked

65,447

Solution 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.

Solution 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

Share:
65,447
Vicky
Author by

Vicky

Updated on July 09, 2022

Comments

  • Vicky
    Vicky almost 2 years

    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.

  • Vicky
    Vicky over 10 years
    Can you enable this programmatically for your web pages?
  • Julian Reschke
    Julian Reschke over 10 years
    It depends on your web server. Usually, it is used automatically when you start sending data without knowing the length.
  • Sz.
    Sz. about 6 years
    "usually in giga" - should be mega, if anything. ;) But it't not even necessarily about size: it's as much about time, so the client can proceed with the received portions, even before knowing the exact size of the whole response.
  • hipeople321
    hipeople321 over 3 years
    @webjockey, I am wondering if the client needs to send data to the server in chunks. It seems like chunking is only implemented by the server.
  • webjockey
    webjockey over 3 years
    web browsers has chunking decoding algorithm in-built as specified in tools.ietf.org/html/rfc7230#section-3.3.1. I am not aware whether web servers implement such algorithm. Alternatively you can use mutipart/form-data with a custom boundary header name but you will have to do your own implementation on how to save the bigfile that is received in chunks delimited by custom boundary header name