Handle Gzip Compressed Response

Fetch gzip-compressed data that is automatically decompressed by the browser.

Code

Utilities
const response = await fetch('https://httpbin.org/gzip');
const data = await response.json();

({
  gzipped: data.gzipped,
  encoding: response.headers.get('content-encoding'),
  method: data.method
});
Browser·fetch() may be limited by CORS

Notes

  • Browser automatically decompresses gzip/deflate/br responses
  • Check Content-Encoding header to see compression used
  • httpbin.org endpoints: /gzip, /deflate, /brotli

More JavaScript Snippets