Enable text compression

Warning: This audit has moved into theDocument request latency insight as of Lighthouse 13. For more information seeWhat's new in Lighthouse 13.

Text-based resources should be served with compression to minimize total networkbytes. The Opportunities section of your Lighthouse report lists all text-basedresources that aren't compressed:

A screenshot of the Lighthouse Enable text compression audit

How Lighthouse handles text compression

Lighthouse gathers all responses that:

  • Have text-based resource types.
  • Do not include acontent-encoding header set tobr,gzip, ordeflate.

Lighthouse then compresses each of these withGZIP to compute the potentialsavings.

If the original size of a response is less than 1.4KiB, or if thepotential compression savings is less than 10% of the original size, thenLighthouse does not flag that response in the results.

Note: The potential savings that Lighthouse lists are the potential savingswhen the response is encoded with GZIP.If Brotli is used, even more savings are possible.

Enable text compression on your server

Enable text compression on the server(s) that served these responses in order topass this audit.

When a browser requests a resource, it will use theAccept-EncodingHTTP request header to indicate what compression algorithms it supports.

Accept-Encoding: gzip, compress, br

If the browser supportsBrotli(br) you should use Brotli because it can reduce the file size of the resources more than theother compression algorithms. Search forhow to enable Brotli compression in <X>, where<X> is the name of your server. As of December 2022 Brotli is supported in all major browsers except Safari on iOS. SeeBrowser compatibilityfor updates.

Use GZIP as a fallback to Brotli. GZIP is supported in all major browsers,but is less efficient than Brotli. Refer toServer Configsfor examples.

Your server should return theContent-EncodingHTTP response header to indicate what compression algorithm it used.

Content-Encoding: br

Check for response compression

To check if a server compressed a response:

PressControl+Shift+J (orCommand+Option+J on Mac) to open DevTools.Click the Network tab.

  1. PressControl+Shift+J (orCommand+Option+J on Mac) to open DevTools.
  2. Click theNetwork tab.
  3. Click the request that caused the response you're interested in.
  4. Click theHeaders tab.
  5. Check thecontent-encoding header in theResponse Headers section.
The content-encoding response header
Thecontent-encoding response header.

To compare the compressed and decompressed sizes of a response:

  1. PressControl+Shift+J (orCommand+Option+J on Mac) to open DevTools.
  2. Click theNetwork tab.
  3. Enable large request rows.SeeUse large request rows.
  4. Look at theSize column for the response you're interested in. Thetop value is the compressed size. The bottom value is the decompressedsize.

See alsoMinify and compress network payloads.

Stack-specific guidance

  • Drupal: Text-based resources should be served with compression (gzip, deflate or brotli) to minimize total network bytes. Consider using a CDN that natively supports this, or configure the web server to perform this operation.Learn more.
  • Joomla: Enable the Gzip Page Compression setting (System >Global configuration >Server).
  • WordPress: Enable text compression in your web server configuration.

Resources

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2019-05-02 UTC.