Files less than 1kB returned by a Worker very slow

We are experiencing a strange issue using Workers. We have a sophisticated Worker which caches most of our content based on different rules. If we are to return a file, which size is less than a kilobyte it gets downloaded, but it takes 30 sec for the browser to close the connection. The content of the file appears immediately, but it looks like if the browser didn’t know the size of the file.
If access the file directly, bypassing the worker, it comes down perfectly.

Have you experienced something similar?

A sample:
https://www.wealthclub.co.uk/assets/favicons/manifest.b5a75fc1bb0b.json
https://live.wealthclub.co.uk/assets/favicons/manifest.b5a75fc1bb0b.json

Hi there,

Neither of those responses contain a Content-Length or Transfer-Encoding header. This means the client won’t know when to close the connection and therefore relies on the server to do so.

If the server doesn’t close the connection after everything has been transmitted, the client will wait until connection timeout - which is most likely after 30 seconds.

Are you modifying the response headers in the Worker or using a Transform Rule which could include removing the Content-Length header?

1 Like

Hi Albert,
thank you for your response, yes, I have noticed that, and that was my initial theory too, but there is no such header in any of our responses.
If you check the network tab loading the first you will see it is “loading” for 30secs, however, the same file (the second URL), by accessing the server directly, finishes instantly.

If the worker is fetching the data from an origin, that origin server need to add the size headers to the response. Most webservers do this automatically, but if you’re returning it directly from Node for example, you need to add it manually.

2 Likes

Thank you for your responses.
Upon further investigation CF ALWAYS removes the Content-Length because of an early technical decision of theirs (Streams based uploading with Content-Length (not chunked encoding) · Issue #95 · whatwg/fetch · GitHub) hence we don’t see it in the streams returned by the worker. (Also if the “Brotli” optimization is enabled, it will recode almost everything into br) So it kindof makes sense, but I still don’t get that when accessing it from origin it always works, though there is no Content-Length there either…