Web Technology Basics
When a web server compresses responses with gzip or Brotli before sending them, which of the following generally gains the least reduction in transferred data from compression?
- AAn HTML file
- BA JavaScript file
- CA JPEG photo
Show answer and explanation
Answer: C. A JPEG photo
The browser states the compression methods it supports with the Accept-Encoding header, and the server indicates the method it used in the compressed response with the Content-Encoding header. Text such as HTML, CSS, JavaScript and JSON contains repeated character sequences, so compression makes it much smaller. Images in JPEG, PNG or WebP, and videos, are already compressed formats, so compressing them again hardly makes them smaller and wastes processing time. For this reason, servers are generally configured to compress only text responses.
- A. HTML is text in which the same tags and words appear repeatedly, so it compresses well.
- B. JavaScript is also text, and compression is very effective for it.
- C. Correct. JPEG is already a compressed format, so compressing it again hardly makes it smaller.