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.
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.
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: BrotliTóm tắt — Compression shrinks của bạn text files — HTML, CSS, JavaScript — trước khi họ’re được gửi over internet, so trình duyệt downloads ít hơn bytes và trang loads nhanh hơn (assuming đó thực ra của bạn bottleneck). hai bạn’ll hear về là Gzip (hoạt động mọi nơi) và Brotli (thường nhỏ hơn, và Google preference) — chính xác Cách nhiều nhỏ hơn varies by file, so không treat bất kỳ một percentage as promise. nếu PageSpeed Insights bao giờ told bạn để “Enable text compression,” (bản dịch) «Enable text compression,» Đây là khắc phục.
Điều gì compression là
Khi ai đó loads của bạn trang, của họ trình duyệt có để download all files đó làm nó up. Compression là way để làm những điều đó files nhỏ hơn trong khi họ travel, sau đó có trình duyệt unpack them tại khác end. Không có gì về trang thay đổi cho khách truy cập — họ chỉ nhận nó nhanh hơn.
nó hoạt động như nhanh handshake on mỗi yêu cầu:
- Đó trình duyệt says, “here’s what I can unpack” (bản dịch) «ở đây điều gì I có thể unpack» — điều này gửi một header called
Accept-Encodinglisting đó algorithms điều này understands (nhưgzipvàbr). - Đó máy chủ picks một, compresses đó file với điều này, và gửi back một
Content-Encodingheader saying mà một điều này dùng. - Đó trình duyệt unpacks điều này và cho thấy đó trang.
đó nó. nó happens tự động, theo file, và bạn turn nó on sau khi trong của bạn máy chủ hoặc hosting settings.
hai bạn cần know
- Gzip — old reliable. mỗi trình duyệt và công cụ tìm kiếm hỗ trợ nó. nó safe default.
- Brotli — newer, developed tại Google, và thường làm text files bit nhỏ hơn hơn Gzip. Khi trình duyệt hỗ trợ Brotli, Google nói để sử dụng nó — với Gzip as fallback cho bất cứ điều gì đó không.
bạn’ll cũng bắt đầu seeing Zstandard (Zstd), thứ ba option đó fast để unpack, nhưng nó vẫn sớm và không widely được sử dụng tuy vậy.
Điều gì compression là không
- nó không minification. Minifying strips out spaces và comments từ của bạn code; compression re-packs bytes cho transfer. họ’re khác jobs, và bạn làm cả hai — minify đầu tiên, sau đó compress.
- nó không bộ nhớ đệm. bộ nhớ đệm saves copy so file không có để là được gửi again. Compression làm file nhỏ hơn Khi nó là được gửi. (See bộ nhớ đệm cho đó side.)
Điều gì để compress — và Điều gì để skip
Compress của bạn text: HTML, CSS, JavaScript, JSON, SVG, và XML files (including sitemaps).
không bother compressing files đó là đã compressed — JPGs, PNGs, GIFs, phần lớn videos, WOFF2 web fonts, và phần lớn PDFs. họ sẽ không nhận nhỏ hơn, và squeezing them again chỉ wastes effort. Google đã làm điều này chính xác point back trong 2008.
Làm nó help SEO?
Indirectly. Compression là không xếp hạng factor on của nó own. nhưng nhỏ hơn files có nghĩa là nhanh hơn loads, và speed feeds Cốt lõi Web Chỉ số quan trọng, mà là part của Cách Google judges trang experience. So bạn enable compression vì nó làm của bạn trang web nhanh hơn — không vì Google cho bạn points cho setting itself.
Muốn thực version — Gzip so với Brotli numbers, chính xác Điều gì Googlebot hỗ trợ và Cách chúng ta know, PageSpeed audit thresholds, compression levels, và Cách enable và verify nó on của bạn máy chủ? Switch để Nâng cao tab.
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: BrotliTL;DR — Compression là HTTP nội dung-encoding negotiation: đó client gửi
Accept-Encoding(mà có thể carryqweights vàidentity), đó máy chủ replies vớiContent-Encoding, theo yêu cầu, theo tài nguyên — và một cacheable phản hồi đó varies by coding cầnVary: 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.
Đ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.
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ó.
#:~: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 compressioncó 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_staticvà Apache’smod_deflatecả 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:
- Apache —
mod_deflatemodule (vàmod_brotlicho 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;plusgzip_types), và Brotli module chobr. - 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
compressionmiddleware; 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 compressionCompression 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.
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.
AI summary
condensed take on Nâng cao version:
- Compression = HTTP nội dung encoding, distinct từ HTTP transfer coding
(RFC 9110, §8,4). Shrinks text các phản hồi (HTML, CSS, JS, JSON, SVG, XML sitemaps)
trước they cross đó network. Negotiated theo yêu cầu: client gửi
Accept-Encoding(có thể carryqweights vàidentity), máy chủ replies vớiContent-Encoding; một cacheable phản hồi đó varies by coding cầnVary: Accept-Encoding(§12.5.5). - Three codecs: Gzip (universal fallback), Brotli (thường nhỏ hơn on text — thường cited ~15–20%, nhưng đó varies by nội dung/codec version/level, không một fixed number — và Google stated preference khi supported), Zstd (registered theo IANA và scoped by RFC 9659, nhưng không universally supported; Google crawler tài liệu không state Zstd hỗ trợ cho Googlebot). Serve Brotli + Gzip fallback together.
- Googlebot hỗ trợ gzip, deflate, và Brotli (
br) — stated plainly trong đó hiện tại crawler tài liệu, 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. Bing có không tương đương crawler-compression doc — assume Gzip từ HTTP các tiêu chuẩn, flag điều này as một khoảng trống. - Không phải là yếu tố xếp hạng, và không một guaranteed speed win. Nhỏ hơn transfer size có thể help TTFB → LCP → Core Web Vitals, nhưng chỉ nếu đó là đó thực tế bottleneck — Google own hướng dẫn bounds đó trực tiếp outcome to ít hơn network bytes, không một promised Core Web Vitals hoặc Tìm kiếm thay đổi. Compression cũng helps HTML stay under Googlebot’s ~2 MB fetch limit (2026 “Inside Googlebot” (bản dịch) «Bên trong Googlebot»), một crawl-efficiency win; over đó limit, fetches là truncated, không rejected.
- Lighthouse “Enable text compression” (bản dịch) «Enable text compression» flags text các phản hồi không có một
br/gzip/deflateencoding, nhưng skips files under ~1,4 KiB hoặc nơi savings là under 10% — đó là này cụ thể audit suppression rule, không một universal size floor (CDNs publish của họ own minimums). Proxies/antivirus có thể stripContent-Encodingvà nguyên nhân một sai negative. - Levels & trade-offs: Gzip 1–9, Brotli 0–11. Cao hơn cho static/pre-compressed assets (cost paid khi tại xây dựng); thấp hơn/mid-range cho dynamic nội dung (CPU/latency) — benchmark so với của bạn own traffic; không level là universally best.
- không blanket-exclude by extension — decide từ MIME loại và measured output; đã-compressed formats (images, video, WOFF2, hầu hết PDFs) rarely benefit.
- BREACH risk là scoped, không một reason to disable compression sitewide: điều này requires một compressed phản hồi mixing một secret với attacker-reflected nội dung và an observable repeated length — review và cách sửa đó cụ thể phản hồi/context.
- Validate đó encoded representation itself:
Vary: Accept-Encodingcho bộ nhớ đệm variants, watch cho double-compression across proxy/CDN/origin hops, và treatETag/Content-Length/range behavior as cụ thể to đó được chọn encoding, không giống hệt across identity/gzip/br. - Sitemap myth busted: đó Sitemaps giao thức explicitly cho phép gzip-compressed
sitemaps (
.xml.gz); uncompressed size limits vẫn apply.
Tài liệu chính thức
Chính-nguồn tài liệu on compression và nội dung encoding.
- Enable text compression (Lighthouse) — đó audit trigger thresholds, Accept-Encoding negotiation, và đó “prefer Brotli, fall back to Gzip” (bản dịch) «ưu tiên Brotli, fall back to Gzip» hướng dẫn.
- Minify và compress network payloads với brotli (web.dev codelab) — Brotli quality levels (0–11) và static-so với-dynamic compression trade-offs, với một trước/sau ví dụ.
- Enable Compression (PageSpeed Insights) — đó “up to 90%” hình, máy chủ modules (mod_deflate, gzip module, IIS), và đó proxy/antivirus sai-negative caveat.
- Google Crawler (Người dùng Agent) Overview — đó definitive “gzip, deflate, and Brotli (br)” (bản dịch) «gzip, deflate, và Brotli (br)» statement và cách các crawler advertise điều này qua Accept-Encoding.
- Đầu tiên date với đó Googlebot: Các header và compression (2008) — Google original lời giải thích of gzip so với deflate và mà file types không benefit từ compression.
Các tiêu chuẩn / giao thức
- RFC 9110 — HTTP Semantics — defines nội dung coding as transformation của representation dữ liệu (§8,4), distinct từ transfer coding;
Accept-Encodingnegotiation vớiqweights vàidentity(§12.5.3); vàVaryrequirement cho bộ nhớ đệm variants đó differ by encoding (§12.5.5). - RFC 9659 — Zstandard (zstd) as HTTP nội dung Coding — cập nhật RFC 8878, sets 8 MB interoperable window requirement cho
zstd, và distinguishes nó từ dictionary codingdcz. - IANA HTTP nội dung Coding Registry — authoritative list của registered coding tokens (
gzip,br,zstd, và others); registration không phải giống nhau as universal client/crawler/CDN hỗ trợ. - Apache
mod_deflatetài liệu —Vary: Accept-Encodingcho compressed bộ nhớ đệm variants, avoiding double-compression của precompressed nội dung,DeflateAlterETag, và BREACH review note. - Cloudflare — nội dung compression — origin/edge transformation behavior, minimum phản hồi size cho compression, và codec selection by plan/rule.
- nginx
ngx_http_gzip_static_module— serving precompressed static files thay vì recompressing theo yêu cầu. - Sitemaps giao thức (sitemaps.org) — xác nhận gzip-compressed sitemap files là được phép, và uncompressed size limits.
Security
- BREACH attack — gốc research — attack thực tế prerequisites: compressed phản hồi mixing secret với attacker-influenced reflected nội dung, observed qua repeated length việc đo lường.
Bing / Microsoft
- Không dedicated Bing document specifies Bingbot’s nội dung-encoding hỗ trợ cho HTML crawling. Bing URL/sitemap submission help xác nhận gzip-compressed sitemap hỗ trợ và Gzip on nội dung Submission API — Bing Quản trị viên web Tools help. Treat crawler-side hỗ trợ as inference từ HTTP các tiêu chuẩn, không được ghi lại statement.
Quotes từ nguồn
On—record statements từ Google. mỗi link với #:~:text= fragment jumps
để quoted passage on nguồn trang.
Google — Lighthouse “Enable text compression” (bản dịch) «Enable text compression»
- “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ợ.» Jump to quote
- “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.» Jump to quote
- “The potential savings that Lighthouse lists are the potential savings when the response is encoded with GZIP. If Brotli is used, even more savings are possible.” (bản dịch) «Đó potential savings đó Lighthouse lists là đó potential savings khi đó phản hồi là encoded với GZIP. Nếu Brotli là dùng, even hơn savings là có thể.» Jump to quote
- “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ả.» Jump to quote
- “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.» … “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.» Jump to quote
Google — PageSpeed Insights “Enable Compression” (bản dịch) «Enable Compression»
- “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%.» Jump to quote
- “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.» Jump to quote
Google — Crawler (Người dùng Agent) Overview
- “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).» Jump to quote
- “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.» Jump to quote
Gary Illyes, Google — Brotli xác nhận (2020)
- Illyes confirmed, sau khi đáp ứng với Googlebot team, đó Googlebot hỗ trợ Brotli compression — posted để X trong August 2020 và reported giống nhau day by Barry Schwartz. (Paraphrased từ báo cáo, không reproduced as verbatim pull-quote ở đây.) đọc coverage
#:~:text= deep links đã không constructed cho đó legacy template, so họ là
paraphrased thay vì quoted. Đó Martin Splitt “what goes over the wire” (bản dịch) «điều gì goes over đó wire» point là
relayed qua Search Engine Journal’s reporting, không một chính transcript, và là
paraphrased. Đó Illyes 2020 xác nhận là relayed qua Công cụ tìm kiếm Roundtable và
paraphrased. Xác nhận any of những so với đó trực tiếp/chính nguồn trước treating as
cuối. Mà compression setup nên I sử dụng?
Bắt đầu từ điều gì bạn là serving và nơi, không từ “Gzip or Brotli?” (bản dịch) «Gzip hoặc Brotli?» — trong thực tế bạn gần như luôn serve cả hai.
Q1. có thể của bạn máy chủ/CDN offer Brotli với Gzip fallback?
- Có (modern Nginx/Apache module, hoặc CDN toggle) → enable Brotli + Gzip.
Negotiation picks Brotli cho clients đó advertise
brvà Gzip cho mọi người khác, tự động. Đây là default câu trả lời. Continue để Q2. - Không (older stack, Brotli module không khả dụng) → enable Gzip alone cho hiện tại. nó supported mọi nơi và captures phần lớn của win. Revisit Khi Bạn có thể thêm Brotli.
Q2. là asset static (được xây dựng ahead của time) hoặc generated theo yêu cầu?
- Static (CSS/JS bundles, prebuilt HTML, sitemaps) → pre-compress tại cao hơn level (up để Gzip 9 / Brotli 11) tại xây dựng time, benchmarked cho của bạn assets. CPU cost là paid sau khi; mỗi yêu cầu nhận nhỏ hơn file.
- Dynamic (theo-yêu cầu HTML từ app/CMS) → compress tại thấp hơn/mid-range level (Brotli ~4 là phổ biến starting point để benchmark từ). Maximum levels thêm thực-time latency để mỗi phản hồi; right level phụ thuộc vào của bạn traffic và CPU headroom, không fixed number.
Q3. là file đã compressed binary? (JPG, PNG, GIF, video, WOFF2, phần lớn PDFs)
- Có → không compress nó. nó sẽ không shrink và bạn’ll waste CPU (và có thể even grow file slightly). Phạm vi của bạn compression rules để text MIME types.
- Không (HTML, CSS, JS, JSON, SVG, XML) → compress nó.
Q4. của bạn PageSpeed báo cáo vẫn nói “Enable text compression” (bản dịch) «Enable text compression» sau khi bạn turned nó on.
- là flagged file under ~1,4 KiB, hoặc sẽ nó save under 10%? → Lighthouse sẽ không flag những điều đó anyway; nếu nó không flagged, có không có gì để khắc phục.
- Kiểm thử với
curl -I -H "Accept-Encoding: br, gzip"và seecontent-encodingheader? → máy chủ là fine; proxy hoặc antivirus on kiểm thử path có khả năng stripped header. Retest từ sạch network. - Không
content-encodingheader tại all → máy chủ genuinely không phải compressing đó phản hồi — kiểm tra của bạn MIME-loại scoping và module config.
Compression setup & verification — checklist
truyền để xác nhận text là compressed, Brotli là được ưu tiên, và không có gì double-compressed:
- Brotli enabled với Gzip fallback — máy chủ advertises
brvà phục vụ Gzip để clients đó không hỗ trợ nó. - Compression scoped để text MIME types — HTML, CSS, JS, JSON, SVG, XML. đã-compressed formats (images, video, WOFF2, phần lớn PDFs) là excluded.
- Static assets pre-compressed tại cao hơn level (up để Gzip 9 / Brotli 11) tại xây dựng time — benchmarked, không chỉ copied từ blog post.
- Dynamic các phản hồi tại thấp hơn/mid-range level để balance CPU/latency, confirmed so với của bạn own traffic.
-
Vary: Accept-Encodingpresent on có thể lưu vào bộ nhớ đệm các phản hồi đó vary by coding, so shared bộ nhớ đệm không phục vụ sai variant. - Không double-compression across proxy/CDN/origin hops, và
Content-Lengthmatches thực tế encoded thân phản hồi tại mỗi hop. - Verified từ command line:
curl -I -H "Accept-Encoding: br, gzip" https://example.com/trả vềcontent-encoding: br(hoặcgzip) header. - Verified trong DevTools — Network tab hiển thị transferred size well dưới tài nguyên size cho text các phản hồi.
- PageSpeed Insights / Lighthouse — không “Enable text compression” (bản dịch) «Enable text compression» flag on text các phản hồi over ~1,4 KiB.
- Sai negative ruled out — nếu checker nói compression là off nhưng curl
hiển thị
content-encodingheader, suspect proxy/antivirus stripping nó trong transit, không máy chủ. - Sitemaps — lớn sitemaps served gzipped (
.xml.gz), với uncompressed file vẫn trong 50 000-URL / 50 MB limits. - Minification đã xong cũng — compression stacks với minification; bạn’re đang làm cả hai, không một thay vì khác.
Compression bảng tra nhanh
** three codecs**
| Codec | Header | Ratio so với Gzip | Hỗ trợ | sử dụng nó cho |
|---|---|---|---|---|
| Gzip | gzip | baseline | Universal | luôn-on fallback |
| Brotli | br | thường nhỏ hơn (thường cited ~15–20%, nhưng varies by nội dung/level) | All major các trình duyệt (Safari iOS đã thêm nó by muộn 2022) | được ưu tiên codec Khi supported |
| Zstd | zstd | Comparable, fast decompress | Registered (RFC 9659) nhưng không universal — không confirmed cho Googlebot | Enable nơi yêu cầu hỗ trợ nó; vẫn thấp adoption |
Compression levels
| Codec | Range | Static assets | Dynamic các phản hồi |
|---|---|---|---|
| Gzip | 1–9 | cao hơn (benchmark) | thấp hơn/mid-range (benchmark) |
| Brotli | 0–11 | cao hơn (benchmark) | commonly ~4 as starting point (benchmark) |
Điều gì để compress so với skip
| Compress | không compress (đã compressed) |
|---|---|
| HTML, CSS, JS | JPG, PNG, GIF |
| JSON, SVG | Video (MP4, WebM) |
| XML / sitemaps | WOFF2 fonts, phần lớn PDFs |
Fast facts
- Googlebot hỗ trợ gzip, deflate, và Brotli (br) — negotiated qua
Accept-Encoding(không confirmed cho Zstd). - Gzip savings ceiling là cited up to ~90% by Google — một ceiling, không một typical number; thực tế savings vary by nội dung và codec.
- Lighthouse skips files < ~1,4 KiB hoặc với < 10% potential savings — đó audit own suppression rule, không một universal minimum size.
- Compression helps HTML stay under Googlebot’s ~2 MB fetch limit (2026) — một crawl-efficiency win; over đó limit, fetches là truncated, không rejected.
- Cacheable các phản hồi đó vary by coding cần
Vary: Accept-Encoding, hoặc một shared bộ nhớ đệm có thể serve đó wrong variant to một client đó không thể decode điều này. - BREACH 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.
- Sitemaps giao thức cho phép gzip (
.xml.gz) — đó “you can’t gzip a sitemap” (bản dịch) «bạn không thể gzip một sitemap» belief là một myth. - Verify:
curl -I -H "Accept-Encoding: br, gzip" <url>→ tìmcontent-encodingvàvary.
Compression myths & mistakes
recurring ones worth un-learning:
- “Enabling compression will boost my rankings.” (bản dịch) «Enabling compression sẽ boost my thứ hạng.» Không nguồn, chính thức hoặc rep, says compression là một tín hiệu xếp hạng. đây là an input to tốc độ trang / Cốt lõi Web Chỉ số quan trọng (trang-experience-liền kề), không một scored factor on của nó own. Enable điều này cho speed, mô tả điều này honestly.
- “Brotli isn’t supported by Google, so stick with Gzip.” (bản dịch) «Brotli không supported by Google, so stick với Gzip.» Outdated. Google crawling infrastructure có supported Brotli since ít nhất 2020 (Illyes) và đây là stated plainly trong đó hiện tại crawler tài liệu. Đó myth survives vì đó news là old và easy to miss.
- “Compressing my images / fonts / videos will speed up the site.” (bản dịch) «Compressing my images / fonts / videos sẽ speed up đó site.» Counter- productive. JPG, PNG, GIF, hầu hết video, và WOFF2 fonts là đã compressed; re-compressing wastes CPU cho negligible hoặc zero gain, và có thể occasionally grow đó file. Phạm vi compression to text.
- “My PageSpeed report says compression is off, but I turned it on — the report’s
broken.” (bản dịch) «My PageSpeed báo cáo says compression là off, nhưng I turned điều này on — đó báo cáo
hỏng.» Không nhất thiết. Theo Google own PSI doc, proxies hoặc antivirus có thể
strip đó
Content-Encodingheader trước đây là measured, producing một sai negative. Kiểm thử từ một sạch path với curl trước blaming đó tool hoặc đó máy chủ. - “Compression and minification are the same thing.” (bản dịch) «Compression và minification là cùng một điều.» Khác nhau stages: minify strips nguồn characters, compression re-encodes bytes cho transfer. They stack — làm cả hai.
- “Maximum compression level is always best.” (bản dịch) «Maximum compression level là luôn best.» Overstated cho dynamic nội dung. Max levels (Gzip 9, Brotli 11) cost real CPU theo yêu cầu; dùng them cho static/pre-compressed assets và một mid-range level cho on-đó-fly các phản hồi.
- “You can’t (or shouldn’t) gzip a sitemap.” (bản dịch) «Bạn không thể (hoặc không nên) gzip một sitemap.» Wrong — đó Sitemaps giao thức
explicitly cho phép gzip-compressed sitemaps (
.xml.gz); chỉ giữ đó uncompressed file trong đó 50 000-URL / 50 MB limits.
Verify negotiated compression từ command line
Chạy on macOS/Linux. --compressed advertises supported encodings và decompresses
thân phản hồi cho display; các header vẫn hiển thị Điều gì traveled over wire.
curl -sS --compressed -D - -o /dev/null https://example.com/app.js
curl -sS -H 'Accept-Encoding: br' -D - -o /dev/null https://example.com/app.js
curl -sS -H 'Accept-Encoding: gzip' -D - -o /dev/null https://example.com/app.js
curl -sS -H 'Accept-Encoding: identity' -D - -o /dev/null https://example.com/app.jscho có thể lưu vào bộ nhớ đệm tài nguyên, phản hồi nên bao gồm appropriate
Content-Encoding và Vary: Accept-Encoding header — kiểm tra đó header
explicitly nếu tài nguyên sits behind shared bộ nhớ đệm hoặc CDN, since của nó absence là
Điều gì lets bộ nhớ đệm phục vụ một client encoded variant để một client đó có thể’t
decode nó.
On Windows PowerShell, yêu cầu mỗi encoding và inspect các header:
$headers = @{ "Accept-Encoding" = "br, gzip" }
$r = Invoke-WebRequest -Uri "https://example.com/app.js" -Headers $headers
$r.Headers | Select-Object Content-Encoding, Vary, Content-Lengthtìm uncompressed giống nhau-origin text các tài nguyên trong DevTools
Paste vào Chrome DevTools Console sau khi trang loads. nó dùng tài nguyên timing sizes as shortlist; xác nhận mỗi phản hồi trong Network panel vì được lưu đệm và cross-origin entries có thể omit sizes.
performance.getEntriesByType('resource')
.filter((r) => r.transferSize > 0 && r.encodedBodySize === r.decodedBodySize)
.map((r) => ({ url: r.name, bytes: r.transferSize }));Extract compression các header trong crawler
sử dụng điều này XPath trong phản hồi-header-aware custom extraction workflow để locate HTML marker chỉ Khi của bạn crawler có stored các header riêng; cho ordinary HTML, compression là HTTP header và không thể là extracted từ DOM itself. đó phân biệt ngăn phổ biến sai kiểm thử: XPath alone không thể prove transfer encoding.
Tools cho kiểm thử HTTP compression
- Chrome DevTools Network panel — inspect
Content-Encoding, transferred size, tài nguyên loại, và liệu CDN/bộ nhớ đệm changed phản hồi. curl --compressed— kiểm thử nội dung thực negotiation và so sánh Brotli, Gzip, và identity các phản hồi không có relying on trình duyệt UI.- PageSpeed Insights / Lighthouse — surface text các tài nguyên đó sẽ save đủ bytes để trigger “Enable text compression” (bản dịch) «Enable text compression» audit described trong bài viết.
- WebPageTest — so sánh transfer sizes và yêu cầu waterfalls under consistent location, trình duyệt, và network profile.
- CDN/máy chủ configuration và nhật ký — xác nhận mà codec và compression level là được chọn cho static versus dynamic các tài nguyên.
Prove compression là configured correctly
Encoding-negotiation kiểm thử
Kiểm thử để chạy: yêu cầu text tài nguyên riêng với Accept-Encoding: br,
gzip, và identity. Dự kiến kết quả: supported các yêu cầu nhận matching
Content-Encoding; identity vẫn decodable và variants bao gồm appropriate
Vary. thất bại interpretation: negotiation, bộ nhớ đệm variation, hoặc origin/CDN
configuration là sai. Monitoring window: immediate sau khi propagation.
Rollback trigger: corrupted các thân phản hồi hoặc variant served với sai encoding.
tài nguyên-phạm vi kiểm thử
Kiểm thử để chạy: sample HTML, CSS, JS, JSON/SVG/XML, plus đã-compressed images, video, và fonts trong Network panel. Dự kiến kết quả: text formats là compressed trong khi formats đó gain không có gì không phải recompressed. thất bại interpretation: MIME-loại allowlist là incomplete hoặc overbroad. Monitoring window: immediate. Rollback trigger: increased transfer size, excessive origin CPU, hoặc hỏng assets.
Performance-regression kiểm thử
Kiểm thử để chạy: so sánh repeatable WebPageTest/Lighthouse chạy và máy chủ CPU trước khi và sau khi enabling dynamic compression. Dự kiến kết quả: text transfer bytes fall không có consistent TTFB hoặc lỗi regression. thất bại interpretation: chosen codec/level costs cũng nhiều CPU hoặc compression là occurring tại sai layer. Monitoring window: lab immediately và production during representative load. Rollback trigger: sustained latency, CPU saturation, hoặc elevated các lỗi.
bộ nhớ đệm-variant (Vary) kiểm thử
Kiểm thử để chạy: cho có thể lưu vào bộ nhớ đệm phản hồi đó served với khác encodings để
khác clients, yêu cầu nó với Accept-Encoding: br, sau đó gzip, sau đó
identity, qua giống nhau bộ nhớ đệm/CDN path. Dự kiến kết quả: mỗi variant xuất hiện
back correctly encoded cho Điều gì là requested, và phản hồi carries
Vary: Accept-Encoding so bộ nhớ đệm mấu chốt bao gồm negotiated coding (RFC 9110,
§12.5.5). thất bại interpretation: shared bộ nhớ đệm là storing một encoded variant
và serving nó để clients đó có thể’t decode nó — kinh điển symptom là client đó
đã không advertise br receiving Brotli thân phản hồi nó có thể’t đọc. Monitoring window:
immediate sau khi bất kỳ CDN/bộ nhớ đệm-layer thay đổi. Rollback trigger: bất kỳ client
receiving thân phản hồi nó đã không advertise hỗ trợ cho, hoặc bộ nhớ đệm hit ratio collapse từ
over-widened bộ nhớ đệm mấu chốt.
Double-transformation và stale-metadata kiểm thử
Kiểm thử để chạy: trace phản hồi qua mỗi proxy/CDN/origin hop (e.g. so sánh
các header tại origin versus tại edge) để xác nhận compression là applied chính xác
sau khi. Dự kiến kết quả: cuối Content-Encoding names một coding, và
Content-Length matches thực tế encoded thân phản hồi được gửi, với không leftover
identity-length header từ trước khi hop transformed thân phản hồi. thất bại
interpretation: intermediary decompressed và recompressed phản hồi (hoặc
compressed đã-compressed thân phản hồi) không có updating length/integrity metadata —
Apache’s mod_deflate và Cloudflare’s compression tài liệu cả hai flag điều này
recompression/metadata-drift scenario explicitly. Monitoring window: sau khi
introducing hoặc thay đổi bất kỳ CDN, reverse proxy, hoặc edge transformation rule.
Rollback trigger: corrupted downloads, mismatched Content-Length, hoặc visibly
double-compressed các thân phản hồi.
Validator và range-yêu cầu kiểm thử
Kiểm thử để chạy: yêu cầu giống nhau tài nguyên với identity, gzip, và br, và
so sánh ETag, Content-Length, và behavior under Range yêu cầu cho mỗi.
Dự kiến kết quả: mỗi encoded representation là được xem như distinct — của nó own
ETag (hoặc explicitly được ghi lại shared-validator policy), đúng Content-Length
cho đó cụ thể encoding, và range semantics applied để được chọn
representation, không assumed giống hệt across identity/gzip/br. thất bại
interpretation: các validator hoặc một phần-nội dung xử lý là được xây dựng assuming single
canonical representation, mà breaks các yêu cầu có điều kiện hoặc byte-range downloads
cho compressed variants. Monitoring window: immediate, và again sau khi bất kỳ thay đổi
để compression config hoặc CDN bộ nhớ đệm rules. Rollback trigger: conditional
các yêu cầu (If-None-Match) hoặc range các yêu cầu returning sai hoặc corrupted các thân phản hồi cho
compressed variant.
Tự kiểm tra: Compression
Five nhanh các câu hỏi on Cách HTTP text compression hoạt động và Điều gì Google hỗ trợ. Pick câu trả lời cho mỗi, sau đó kiểm tra.
Nhật ký thay đổi
Đã cập nhật 8 thg 8, 2026.
Tóm tắt biên tập và chi tiết thay đổi đã ghi nhận.Chi tiết thay đổi
-
Ghi chú thay đổi chi tiết hiện chỉ có bằng tiếng Anh.
Không thể so sánh đầy đủ — không có bản lưu trước đó cho lần sửa đổi này.
Đã cập nhật 17 thg 7, 2026.
Tóm tắt biên tập và chi tiết thay đổi đã ghi nhận.Chi tiết thay đổi
-
Ghi chú thay đổi chi tiết hiện chỉ có bằng tiếng Anh.
-
Ghi chú thay đổi chi tiết hiện chỉ có bằng tiếng Anh.
-
Ghi chú thay đổi chi tiết hiện chỉ có bằng tiếng Anh.
-
Ghi chú thay đổi chi tiết hiện chỉ có bằng tiếng Anh.
Không thể so sánh đầy đủ — không có bản lưu trước đó cho lần sửa đổi này.