Mondoze Knowledge Base

Search our articles or browse by category below

Why is my dynamic content being sent with chunked encoding?

Last modified: October 5, 2022
You are here:
Estimated reading time: 1 min

Why is my Dynamic Content being Sent with Chunked Encoding?

If you have resources that do not have a file extension that Cloudflare caches we treat that resource as dynamic HTML. We don’t cache it by default, and Cloudflare’s system will send that resource gzipped and with chunked encoding. 

Note — it isn’t possible to have chunk encoding and content-length at the same time so this would explain why content-length would not be sent with these dynamic resource passing through Cloudflare.

Note — Another reason you would not see a content-length header would be if you are sending HTTP 1.1 from your web server. For version 1.1 of the HTTP protocol, the chunked transfer mechanism is consider to be always acceptable. Even if not list in the TE request header field, and when use with other transfer mechanisms, should always be apply last to the transferred data and never more than one time. (Source: wikipedia “Chunked Encoding”).  In this case you need to make sure  is sending HTTP 1.0 as the protocol from your web server. If you specifically need the content-length header.

The solution / workaround – If you add a file extension to the resource so that it matches our list of supported file extensions. So example.com/test/dynamicallyimage.php?size=3 becomes example.com/dynamicallyimage.jpg . Cloudflare’s system will send it with the content-length header. As long as you’re also sending HTTP 1.0 as the protocol.

Alternatively you could use a PageRule and use the “custom caching” option to select “cache everything”. After that, it will force our system to cache example.com/test/dynamicallyimage.php?size=3. Even though it doesn’t have one of our usual file extensions — in this case the content-length will also be preserved.

Was this article helpful?
Dislike 0
Views: 267