Add unpacked Content-Length header for json files

Briefly summarize the issues you have been experiencing.
I am trying to achieve progress loading with fetch and it not working correctly because Netlify server returns Content-Length for gzip packed data. Can netlify server add content length for unpacked data too?

Please provide a link to your live site hosted on Netlify

What have you tried as far as troubleshooting goes? Do you have an idea what is causing the problem?

Do you have any other information that is relevant, such as links to docs, libraries, or other resources?

We cannot easily change the behavior of the service that sets the header, or fails to - I learned this in the past last time someone asked. I don’t have any great suggestions for a workaround on your mission either :frowning:

Maybe someone else in the community can speak to a different process than fetch and how it can work with chunked responses though?

I had the same problem but managed to come up with a rather brute-force solution. I needed to ajax some txt files in the background and I wanted to add a progress bar. As plain text files don’t get the Content-Length header I couldn’t calculate the percentage of the download.

The thing I did, is to save my UTF-8 text file with a “.png” extension. This way Netlify thinks it is an image, gzips it, and adds the header. Ajax will just return the text content that can be either used directly or blob saved with the “.txt” extension.

This might not work in some cases, but I think it worths a try.

1 Like

This is an awesome workaround, thanks for chiming in