Hướng dẫn về Compression (Gzip, Brotli, Zstd)

Cách HTTP text compression hoạt động — Gzip so với Brotli so với Zstd, điều gì Googlebot thực ra hỗ trợ, cách điều này feeds Core Web Vitals và crawler fetch limits, và cách enable và verify điều này by máy chủ. Đó web-performance deep dive on shrinking bytes on đó wire.

Xuất bản lần đầu: 3 thg 7, 2026 · Cập nhật lần cuối: 8 thg 8, 2026 · Advanced
Ngôn ngữ

Compression (HTTP nội dung encoding) shrinks text-based các phản hồi — HTML, CSS, JS, JSON, SVG, XML sitemaps — trước they cross đó network, negotiated theo yêu cầu qua Accept-Encoding / Nội dung-Encoding, với Vary: Accept-Encoding needed to giữ được lưu đệm variants straight. Brotli thường làm tốt hơn hơn Gzip on text (thường cited khoảng 15–20% nhỏ hơn, nhưng đó là directional, không một guaranteed ratio) và là Google stated preference khi đó client hỗ trợ điều này; Gzip là đó universal fallback; Zstd là một registered nhưng không universally supported third codec, và Google crawler tài liệu không state Zstd hỗ trợ cho Googlebot. Googlebot explicitly hỗ trợ gzip, deflate, và Brotli (br) — stated plainly trong Google hiện tại crawler tài liệu, informally confirmed by Gary Illyes trong 2020, và rooted trong Google 2008 'Đầu tiên date với đó Googlebot' post. Compression không một xếp hạng factor và không bảo đảm một TTFB/LCP hoặc Tìm kiếm improvement on của nó own; điều này reduces transfer size, mà có thể help TTFB và LCP nếu đó là thực ra của bạn bottleneck, và điều này helps các trang stay under Google fetch limit (2 MB cho HTML theo Illyes' 2026 'Bên trong Googlebot' post). không blanket-exclude formats by extension alone — decide từ MIME loại và measured output; đã-compressed formats (images, video, WOFF2, hầu hết PDFs) rarely benefit. Dùng cao hơn compression cho static/pre-compressed assets và một thấp hơn/mid-range level cho dynamic nội dung, benchmarked so với của bạn own traffic và CPU headroom — không single level là universally best. BREACH-style risk là scoped to các phản hồi đó mix một secret với attacker-reflected nội dung, không một reason to disable compression sitewide. Và có — đó Sitemaps giao thức explicitly cho phép gzip-compressed sitemaps.

TL;DR — Compression là HTTP nội dung-encoding negotiation: đó client gửi Accept-Encoding (mà có thể carry q weights và identity), đó máy chủ replies với Content-Encoding, theo yêu cầu, theo tài nguyên — và một cacheable phản hồi đó varies by coding cần Vary: Accept-Encoding. Brotli thường beats Gzip on đó giống nhau text (thường cited khoảng 15–20%, though đó chính xác margin phụ thuộc vào nội dung, codec version, và level) và là Google stated preference khi supported; Gzip là đó universal fallback; Zstd là một registered nhưng không universally supported third codec (Google crawler tài liệu không state Zstd hỗ trợ cho Googlebot). Googlebot hỗ trợ gzip, deflate, và Brotli (br) — plainly được ghi lại hôm nay, informally confirmed by Gary Illyes trong 2020, và rooted trong Google 2008 “First date with the Googlebot” (bản dịch) «Đầu tiên date với đó Googlebot» post. Compression không một xếp hạng factor và không bảo đảm một TTFB/LCP hoặc Tìm kiếm thay đổi on của nó own; điều này shrinks transfer size, mà có thể help TTFB → LCP nếu đó là của bạn thực tế bottleneck, và điều này helps các trang stay under Google fetch limit (2 MB cho HTML theo đó 2026 “Inside Googlebot” (bản dịch) «Bên trong Googlebot» post) — một crawl-efficiency win, không chỉ một speed một. Decide điều cần (không) compress từ MIME loại và measured output, không một blanket extension list; BREACH-style risk là scoped to các phản hồi mixing một secret với attacker-reflected nội dung, không một reason to disable compression sitewide. Dùng cao hơn compression cho static/pre-compressed assets, một thấp hơn/mid-range level cho dynamic nội dung — benchmarked so với của bạn own traffic và CPU, since không single level là universally best. Và đó Sitemaps giao thức explicitly cho phép gzip-compressed sitemaps.

Evidence for this claim HTTP content coding compresses transferred representations and is negotiated with Accept-Encoding and Content-Encoding. Scope: Current official or standards documentation. Confidence: high · Verified: MDN: HTTP compression Evidence for this claim Brotli is an HTTP content coding supported through the br encoding token. Scope: Current official or standards documentation. Confidence: high · Verified: RFC 7932: Brotli

Điều gì compression thực ra là

Compression — properly, HTTP nội dung encoding — shrinks một text-based phản hồi thân phản hồi trước điều này crosses đó network, so đó client downloads ít hơn bytes và decompresses them locally. đây là negotiated theo yêu cầu. As Google Lighthouse tài liệu mô tả điều này: “When a browser requests a resource, it will use the Accept-Encoding HTTP request header to indicate what compression algorithms it supports.” (bản dịch) «Khi một trình duyệt các yêu cầu một tài nguyên, điều này sẽ dùng đó Accept-Encoding HTTP header yêu cầu to indicate điều gì compression algorithms điều này hỗ trợ.» MỘT typical header looks như Accept-Encoding: gzip, deflate, br. Đó máy chủ picks một và các tín hiệu của nó lựa chọn back trong đó Content-Encoding header phản hồi.

Hai boundaries worth đang precise về, straight từ đó HTTP đặc tả (RFC 9110): nội dung coding là một transformation of đó representation dữ liệu — đó thân phản hồi — và đó là một khác nhau điều từ transfer coding, mà operates on đó message as điều này moves across một connection. Compression as discussed on này trang là nội dung coding, identified by Content-Encoding. Đó negotiation itself không chỉ một flat list — Accept-Encoding có thể carry weights (q các giá trị) xếp hạng một client preference among đó codings đây là willing to accept, và điều này có thể cũng express một refusal (q=0); identity là đó token cho “no coding applied.” (bản dịch) «không coding applied.» (RFC 9110, §8,4 và §12.5.3.) Và nếu một cacheable thân phản hồi thực ra differs by đó negotiated coding — một gzip variant và một Brotli variant of đó giống nhau URL, say — đó phản hồi cần Vary: Accept-Encoding so một bộ nhớ đệm không serve đó wrong variant to một client đó không thể decode điều này (RFC 9110, §12.5.5; Apache’s mod_deflate tài liệu mô tả này chính xác Vary requirement cho compressed bộ nhớ đệm variants).

Điều này áp dụng to text: HTML, CSS, JavaScript, JSON, SVG, và XML (sitemaps được bao gồm). Cả hai Gzip và Brotli có thể shrink text assets substantially — Google own PageSpeed hướng dẫn cites một ceiling: “Enabling gzip compression can reduce the size of the transferred response by up to 90%.” (bản dịch) «Enabling gzip compression có thể reduce đó size of đó transferred phản hồi by up to 90%.» Treat đó as một ceiling, không một typical number — đó thực tế savings on any được cho phản hồi phụ thuộc on đó nội dung redundancy, của nó size, liệu điều này đã là đã minified, đó codec/version và dictionary dùng, và đó compression level, so they không thể là generalized từ một site numbers to another.

Hai điều nó là không, và cả hai quan trọng:

  • Không minification. Minification xóa characters từ đó nguồn (whitespace, comments); compression re-encodes đó resulting bytes cho transfer. They stack — minify đầu tiên, thì compress — và skipping either leaves savings on đó bảng.
  • Không bộ nhớ đệm. Compression là về encoding (shrinking bytes on đó wire); bộ nhớ đệm là về storage và reuse (Cache-Control, ETag, CDNs). họ là complementary “how bytes get to the browser efficiently” (bản dịch) «cách bytes nhận to đó trình duyệt efficiently» levers. See bộ nhớ đệm cho đó storage side.

điều này trang là compression deep dive under cốt yếu kết xuất path hub, mà lists “compress text” (bản dịch) «compress text» as một bullet trong của nó rộng hơn cốt yếu-bytes checklist. Đây là nơi đó bullet nhận của nó đầy đủ treatment.

Gzip so với Brotli so với Zstd

Compression ratio

Brotli generally làm tốt hơn on text, nhưng không treat any cụ thể number as universal. Google Lighthouse doc là rõ ràng đó đó audit reported savings là computed với Gzip, và “if Brotli is used, even more savings are possible.” (bản dịch) «nếu Brotli là dùng, even hơn savings là có thể.» Google own web.dev Brotli codelab cho thấy một concrete ví dụ: một main.bundle.js đó đã là 225 KB uncompressed came xuống to roughly 61,6 KB với Gzip và về 53,1 KB với Brotli — về 14% nhỏ hơn với Brotli on đó một file. Numbers như đó (và đó “~15–20%” hình bạn’ll see elsewhere) là directional, không phải là bảo đảm — đó real margin on any được cho asset phụ thuộc vào đó codec/library version, đó compression level chosen, đó nội dung redundancy, và liệu điều này đã là đã minified. Không codec hoặc quality level là “luôn best” independent of điều gì bạn là compressing; benchmark của bạn own assets thay vì porting ai đó khác percentage.

Gzip là đó universal fallback. đây là supported mọi nơi, mà là chính xác vì sao Google khuyến nghị điều này as đó safety net: “Use GZIP as a fallback to Brotli. GZIP is supported in all major browsers, but is less efficient than Brotli.” (bản dịch) «Dùng GZIP as một fallback to Brotli. GZIP là supported trong all major các trình duyệt, nhưng là ít hơn efficient hơn Brotli.»

Zstd là thứ ba registered codec, không tuy vậy safe default. IANA HTTP nội dung coding registry lists gzip, br, và zstd — nhưng registration trong đó list không phải giống nhau as universal client, crawler, origin, hoặc CDN hỗ trợ, so chỉ advertise Điều gì được cho yêu cầu có thực ra asked cho và giữ hoạt động fallback path. cho HTTP interoperability cụ thể, RFC 9659 (mà cập nhật trước đó RFC 8878 zstd registration) requires decoders để hỗ trợ windows qua 8 MB và forbids encoders từ requiring lớn hơn window hơn đó — worth knowing nếu bạn’re configuring máy chủ hoặc CDN cho nó. đó HTTP nội dung coding, zstd, là cũng distinct điều từ dictionary-based compression coding dcz; không conflate hai Khi reading vendor tài liệu. thực-world adoption là vẫn sớm (Caddy, cho instance, exposes encode zstd gzip), và Google hiện tại crawler tài liệu lists gzip, deflate, và Brotli cho của nó các crawler và fetchers — nó làm không state Zstandard hỗ trợ cho Googlebot, so không assume nó part của đó lineup. Treat Zstd as một để watch và enable nơi của bạn stack hỗ trợ nó và yêu cầu asks cho nó, không as Gzip/Brotli replacement tuy vậy.

Evidence for this claim gzip, br and zstd are registered HTTP content codings, but registration is not universal client, crawler, origin or CDN support; deploy only a coding advertised for the individual request and preserve a valid identity or fallback path. For HTTP interoperability, RFC 9659 requires zstd decoders to support windows through 8 MB and encoders not to require larger windows; this `zstd` coding is distinct from dictionary coding `dcz`. Scope: registry Confidence: high · Verified: HTTP Content Coding Registry

trình duyệt và crawler hỗ trợ

Brotli hỗ trợ là hiện tại effectively universal trong các trình duyệt, nhưng đó đã không luôn đúng — và đó lịch sử khoảng trống là worth knowing vì đây là vì sao Gzip fallback vẫn matters. Google Lighthouse doc notes: “As of December 2022 Brotli is supported in all major browsers except Safari on iOS.” (bản dịch) «As of December 2022 Brotli là supported trong all major các trình duyệt except Safari on iOS.» Đó Safari-on-iOS khoảng trống là đó canonical ví dụ of vì sao bạn giữ Gzip trong đó chain.

Google khuyến nghị Brotli bất cứ khi nào đó client có thể take điều này: “If the browser supports Brotli (br) you should use Brotli because it can reduce the file size of the resources more than the other compression algorithms.” (bản dịch) «Nếu đó trình duyệt hỗ trợ Brotli (br) bạn nên dùng Brotli vì điều này có thể reduce đó file size of đó các tài nguyên hơn đó other compression algorithms.»

Khi để vẫn fall back để Gzip

luôn giữ Gzip configured alongside Brotli. nội dung-encoding là negotiated theo yêu cầu, so properly configured máy chủ phục vụ Brotli để clients đó advertise br và Gzip để mọi người khác tự động — bạn’re không chọn một hoặc khác, bạn’re offering cả hai và letting handshake quyết định.

Làm Google (và Bing) hỗ trợ Brotli và Gzip?

Đây là câu hỏi phần lớn compression các bài viết assert không có evidence. Ở đây nó là với dated, three-point trail của Google own statements.

Đó 2008 “First date with the Googlebot” (bản dịch) «Đầu tiên date với đó Googlebot» post

Google có explained compression trong của nó own voice since 2008. Trong đầu tiên date với Googlebot: Các header và compression (Maile Ohye và Jeremy Lilley), Google wrote đó all major các công cụ tìm kiếm và web các trình duyệt hỗ trợ gzip compression để save bandwidth, và đó bạn có thể cũng see x-gzip (giống nhau as gzip), deflate (mà Google cũng hỗ trợ), và identity (none). giống nhau post là nơi Google giải thích đó nhiều file formats — Flash, JPG, PNG, GIF, PDF — là đã compressed, so có little để gain từ compressing them again. nó even trạng thái mild preference cho gzip over deflate on robustness grounds (gzip carries checksum và đầy đủ header, leaving ít hơn guesswork). nó old post với “outdated” banner, nhưng thân phản hồi là trực tiếp và trực tiếp on-topic, và gần như không hiện tại bài viết cites nó.

2008 post là quoted ở đây không có quotation marks / deep links: brief verified những điều này lines as chính xác substrings qua trực tiếp fetch, nhưng formal #:~:text= fragment links đã không constructed cho đó legacy template, so họ’re paraphrased thay vì presented as verbatim pull-quotes.

Gary Illyes’ 2020 Brotli xác nhận

Brotli hỗ trợ cho Googlebot là confirmed informally trước khi nó là formally được ghi lại. Trong August 2020, Google Gary Illyes đã nói, sau khi đáp ứng với Googlebot team, đó he’d là asked một vài weeks trước đó liệu Googlebot hỗ trợ Brotli compression — và nó làm. Barry Schwartz reported nó giống nhau day tại công cụ tìm kiếm Roundtable. đó có trước hiện tại crawler-overview tài liệu by về four năm — nice reminder đó rep có thể xác nhận crawler behavior dài trước khi nó lands trong tài liệu.

hiện tại chính thức crawler tài liệu

Hôm nay đây là stated plainly. Google Crawler (Người dùng Agent) Overview says: “Google’s crawlers and fetchers support the following content encodings (compressions): gzip, deflate, and Brotli (br).” (bản dịch) «Google các crawler và fetchers hỗ trợ đó sau nội dung encodings (compressions): gzip, deflate, và Brotli (br).» Và điều này giải thích đó theo-yêu cầu negotiation cùng cách một trình duyệt làm: “The content encodings supported by each Google user agent is advertised in the Accept-Encoding header of each request they make. For example, Accept-Encoding: gzip, deflate, br.” (bản dịch) «Đó nội dung encodings supported by mỗi Google người dùng agent là advertised trong đó Accept-Encoding header of mỗi yêu cầu they làm. Ví dụ, Accept-Encoding: gzip, deflate, br.» I say cùng một điều trong my Ahrefs Googlebot hướng dẫn, mà có một dedicated nội dung-encoding section: “Googlebot supports gzip, deflate, and Brotli (br).” (bản dịch) «Googlebot hỗ trợ gzip, deflate, và Brotli (br).»

So lineage là: 2008 blog post → 2020 Illyes xác nhận → hiện tại crawler tài liệu. Đây là well-established, không speculative.

Bing tài liệu khoảng trống

Bing là honest asterisk ở đây. có không detailed, công khai Bing document stating mà nội dung encodings Bingbot negotiates Khi crawling ordinary HTML — không có gì tương đương để Google crawler-overview trang. Điều gì Bing làm document là hẹp hơn: của nó nội dung Submission API hỗ trợ Gzip, và Bạn có thể submit gzip-compressed sitemap files (.xml.gz) để Bing. vì HTTP compression là tiêu chuẩn mechanism đó essentially all modern clients negotiate qua Accept-Encoding, nó reasonable để assume Bingbot xử lý Gzip tại minimum — nhưng treat đó as inference từ Cách HTTP hoạt động, không as được ghi lại Bing statement. nó genuine tài liệu-transparency khoảng trống giữa hai engines, không knock on Bingbot’s thực tế behavior.

Vì sao compression matters cho performance và Cốt lõi Web Chỉ số quan trọng

causal chain (state nó precisely)

Compression là không một trực tiếp xếp hạng factor. Đó mechanism điều này feeds là: nhỏ hơn transfer size có thể shorten download time, mà có thể help Time to Đầu tiên Byte và downstream Largest Contentful Paint, mà factor vào Core Web Vitals — một trang-experience tín hiệu. Note đó “có thể”: Google own hướng dẫn bounds đó guaranteed outcome to ít hơn network bytes, không một guaranteed TTFB/LCP win, tốt hơn Cốt lõi Web Chỉ số quan trọng, hoặc một Tìm kiếm thay đổi — nếu của bạn load là bottlenecked elsewhere (một chậm database query, một render-blocking script, DNS/connection setup), compressing an đã-nhỏ phản hồi sẽ không move đó needle. Đo lường của bạn own bottleneck và trường outcome rather hơn assuming compression alone các cách sửa speed. Đó điều đó là scored là đó speed outcome, không đó compression setting. Getting này right matters vì một lot of đối thủ nội dung conflates “helps SEO” với “ranking factor.” (bản dịch) «xếp hạng factor.» (See Time to Đầu tiên Byte, Largest Contentful Paint, và Core Web Vitals.)

Evidence for this claim Reducing transferred bytes may improve a network-bound load, but compression alone does not guarantee lower TTFB/LCP, better Core Web Vitals or a Search change; measure the actual bottleneck and field outcome. Scope: lab audit Confidence: high · Verified: Enable text compression

có nice framing từ Google Martin Splitt on Vì sao thô trang weight là misleading way để think về điều này: Điều gì matters là Điều gì thực ra goes over wire sau khi compression, không uncompressed size on disk — trang đó looks như 10 MB uncompressed có thể là five hoặc six over network. đó Splitt point là relayed qua công cụ tìm kiếm Journal reporting thay vì chính transcript, so nó paraphrased ở đây, không quoted.

Compression và hiệu quả crawl — underrated angle

Compression không chỉ về tốc độ trang cho humans. Điều này cũng giúp bạn stay under Google fetch limit. As of đó 2026 “Inside Googlebot” (bản dịch) «Bên trong Googlebot» cập nhật (Gary Illyes), Googlebot fetches roughly 2 MB theo URL cho HTML (xuống từ đó older 15 MB hình), và nội dung beyond đó limit là truncated, không rejected — chỉ đó downloaded portion là đã truyền on cho lập chỉ mục. Compressing của bạn HTML là một of đó levers đó giữ cốt yếu nội dung bên trong đó budget, so này là một crawl-efficiency concern, không chỉ một Core Web Vitals một. (Hơn on đó limit trong crawling.)

Lighthouse “Enable text compression” (bản dịch) «Enable text compression» audit — chính xác thresholds

Đó PageSpeed Insights / Lighthouse “Enable text compression” (bản dịch) «Enable text compression» audit có precise trigger rules worth naming. Lighthouse gathers text-based các phản hồi đó không đã carry một content-encoding of br, gzip, hoặc deflate, compresses mỗi một với Gzip to estimate savings, và — theo Google doc — “If the original size of a response is less than 1.4KiB, or if the potential compression savings is less than 10% of the original size, then Lighthouse does not flag that response in the results.” (bản dịch) «Nếu đó original size of một phản hồi là ít hơn hơn 1,4KiB, hoặc nếu đó potential compression savings là ít hơn hơn 10% of đó original size, thì Lighthouse không flag đó phản hồi trong đó kết quả.» So nhỏ files dưới ~1,4 KiB sẽ không trip đó warning even uncompressed. (As of Lighthouse 13 này audit đã là folded vào đó rộng hơn “Document request latency” (bản dịch) «Document yêu cầu latency» insight, nhưng đó underlying hướng dẫn là unchanged.)

Vì sao correctly-configured trang web có thể vẫn fail audit

MỘT genuinely hữu ích khắc phục sự cố nugget straight từ Google PageSpeed tài liệu: “Proxy servers and anti-virus software can disable compression when files are downloaded to a client machine.” (bản dịch) «Proxy các máy chủ và anti-virus software có thể disable compression khi files là downloaded to một client machine.» Đó có nghĩa là một compression checker có thể báo cáo một sai negative — “compression isn’t enabled” (bản dịch) «compression không enabled» — even khi máy chủ của bạn là configured correctly, vì an intermediary stripped đó Content-Encoding header trong transit. Trước khi bạn assume đó báo cáo là hỏng hoặc đó máy chủ của bạn là misconfigured, kiểm thử từ một sạch network path.

Static so với dynamic compression — implementation trade-offs

Compression levels

Cả hai algorithms có adjustable levels trading CPU time so với ratio:

  • Gzip: levels 1–9.
  • Brotli: levels 0 (không compression) để 11 (maximum), theo Google web.dev codelab.

Cao hơn levels squeeze harder nhưng cost nhiều hơn CPU time.

CPU cost — và Vì sao static so với dynamic matters

Compression không phải free; nó burns CPU, và cost profile là completely khác cho pre-được xây dựng assets versus nội dung generated on fly. right setting không phải single universal number cho either case — nó phụ thuộc vào Cách thường underlying nội dung thay đổi, Cách của bạn bộ nhớ đệm/CDN layer xử lý compressed variant, của bạn traffic volume, và Điều gì bạn thực ra đo lường, không chỉ rule của thumb copied từ blog post.

  • Static (pre-compressed / xây dựng-time) assets — nội dung đó ổn định đủ để compress sau khi ahead của time (nginx gzip_static và Apache’s mod_deflate cả hai document selecting precompressed file thay vì recompressing theo yêu cầu) có thể afford cao hơn compression levels, vì CPU cost là paid sau khi tại xây dựng time thay vì on mỗi yêu cầu. As web.dev codelab puts nó, Khi compression happens ahead của time, latency từ cao compression levels không phải concern anymore; trade-off shifts để lâu hơn xây dựng times, mà bạn pay sau khi, không theo khách truy cập.
  • Dynamic (generated-theo-yêu cầu) các phản hồi — compressing tại highest levels trong thực time adds latency để mỗi phản hồi, so thấp hơn/mid-range level là phổ biến starting point (tooling đôi khi defaults Brotli để khoảng quality 4 cho dynamic nội dung as starting ratio-so với-speed balance) — nhưng treat đó as starting point để benchmark so với của bạn own CPU headroom và traffic, không fixed rule. Google flagged điều này trade-off as far back as 2008 post: enabling gzip/deflate có CPU cost, và on máy chủ đã heavily CPU-loaded serving dynamic nội dung, nó worth weighing trước khi chuyển thành maximum compression on cho mọi thứ.

practical starting point là cao hơn cho static, thấp hơn/mid-range cho dynamic — nhưng xác nhận nó so với của bạn own mutability, bộ nhớ đệm/CDN behavior, traffic, và measured trước khi/sau khi, không level number lifted từ bài viết (including điều này một).

Cách enable compression

mechanism là giống nhau mọi nơi — configure máy chủ (hoặc CDN/edge) để compress text các phản hồi và advertise Brotli với Gzip fallback. By nền tảng:

  • Apachemod_deflate module (và mod_brotli cho Brotli). Google PageSpeed hướng dẫn points ở đây trực tiếp.
  • Nginx — được xây dựng-trong ngx_http_gzip_module (gzip on; plus gzip_types), và Brotli module cho br.
  • IIS — được xây dựng-trong HTTP Compression (static và dynamic).
  • CDN / edge — Cloudflare, Fastly, và similar typically offer Brotli + Gzip as toggle; Caddy exposes encode zstd gzip.
  • App các framework — Node/Express compression middleware; tiếp theo.js/Vercel và phần lớn modern hosts compress theo mặc định.

sau đó verify nó (see Checklists lens cho chính xác commands). fastest kiểm tra: curl -I -H "Accept-Encoding: br, gzip" https://example.com/ và look cho content-encoding header trong phản hồi.

Điều gì không để compress

không re-compress đã-compressed formats: JPG, PNG, GIF, hầu hết video, WOFF2 fonts, và hầu hết PDFs. họ là đã compressed internally; đang chạy Gzip hoặc Brotli over them again spends CPU cho negligible — occasionally negative — size thay đổi. Treat đó list as các ví dụ, không an exhaustive rulebook — GTmetrix own khắc phục sự cố hướng dẫn frames điều này cùng cách: đã-compressed hoặc cao-entropy formats “may not benefit and can grow.” (bản dịch) «có thể không benefit và có thể grow.» Đó safer chung rule là to phạm vi compression by MIME loại (text-based formats) và, nơi bạn có thể, kiểm tra đó measured output cho một được cho phản hồi thay vì trusting một blanket file-extension list, since format và nội dung vary.

có cũng không single universal minimum phản hồi size dưới mà compression “doesn’t count” (bản dịch) «không count» — framing và metadata overhead có thể erase đó savings on nhỏ hoặc đã-dense các thân phản hồi, nhưng nơi đó break-even point sits phụ thuộc vào đó codec, đó implementation, đó các header phản hồi, và đó nội dung itself. Lighthouse own 1,4 KiB / 10%-savings thresholds (trên) là đó cụ thể audit suppression rule, không một chung size floor — một CDN có thể (và thường làm) publish của nó own, khác nhau minimum cho khi điều này sẽ bother compressing một phản hồi tại all.

Evidence for this claim Framing and metadata overhead can erase savings for small or poorly compressible bodies; there is no universal minimum response size because codec, implementation, headers and content determine the break-even point. Scope: lab audit Confidence: high · Verified: Enable text compression

Compression và BREACH — scoped, không reason để disable compression sitewide

bạn có thể see security advice suggesting bạn turn compression off out của caution. không generalize từ đó. BREACH-style risk không phải property của “compression” trong abstract — gốc research mô tả cụ thể attack shape: HTTP phản hồi đó (1) là compressed, (2) mixes secret (như CSRF token) với (3) attacker-influenced nội dung reflected vào giống nhau phản hồi, nơi (4) attacker có thể observe compressed phản hồi length across repeated các yêu cầu để infer secret byte by byte. Apache’s mod_deflate tài liệu flags chính xác điều này combination as worth BREACH-cụ thể review. nếu của bạn các phản hồi không combine secret với attacker-controlled reflected input trong compressed thân phản hồi, kinh điển attack không apply — khắc phục là để review và mitigate cụ thể vulnerable phản hồi/context (e.g. không reflect người dùng input alongside secrets, thêm theo-yêu cầu tokens, hoặc rate-limit), không để disable text compression across toàn bộ trang web.

Evidence for this claim BREACH-style risk is not a reason to disable compression sitewide: the classic attack requires a compressible HTTP response that combines a secret with attacker-influenced reflection and observable repeated length; mitigate the vulnerable response/context with reviewed controls. Scope: security Confidence: high · Verified: BREACH: Reviving the CRIME Attack

sitemap myth — compression là explicitly được phép

Một correction worth đang làm loudly: ** Sitemaps giao thức explicitly cho phép gzip-compressed sitemaps.** Some folks believe Bạn có thể’t hoặc không nên gzip sitemap file — đó sai. sitemaps.org giao thức permits gzipped sitemap files (.xml.gz) để reduce bandwidth, cả hai engines accept them, và Bing own submission tooling hỗ trợ gzip cũng. chỉ caveat là thông thường một: uncompressed sitemap phải vẫn respect giao thức size limits (50 000 các URL / 50 MB uncompressed). Gzipping file on wire là fine và encouraged cho lớn sitemaps.

nơi compression sits trong web performance

Compression là một lever among cluster siblings. nó shrinks cốt yếu bytes cốt yếu kết xuất path có để download; nó lowers TTFB và downstream LCP; nó named PageSpeed Insights / Lighthouse audit; và nó pairs với bộ nhớ đệm (encoding so với storage) và render-blocking các tài nguyên (nhỏ hơn blocking files paint sooner). cho rộng hơn toolkit, see web performance tools.

Add an expert note

Pin an expert quote

New person? Create their unclaimed profile at /admin/experts/ → Pin a quote first.