Get Content-Length using js fetch

Hi everyone, I’m trying to make a progress-bar that keeps track of the download progress.

Underneath there is the API call I make, how can I get the Content-Lenght of the data I’m downloading?

let response = await fetch('https://api.openchargemap.io/v3/poi?output=geojson&key=placeholder&maxresults=250&distanceunit=km&countrycode=IT');

Hi, our API does not currently serve a content-length header and we don’t have any plans to do that. The actual transfer content length varies depending on the delivery mechanism and the client support for different compression and http protocol variations, this is further varied because our data is served via our API through Cloudflare workers which performs other optimizations and protocol upgrades.

If you need to show a determinate progress bar (because the download will take a long time and you wish to show % completed) this is indicative that are querying for too much data in one go. Our entire data set would be more than 120MB and take over a minute to transfer, but that depends on your use case. Note that it’s inappropriate to use our API to repeatedly query large data sets and if that’s required you should mirror the data to your own API/datastore.