---
title: Brotli 与 Zstandard 压缩:Content-Encoding 与服务器部署
keywords:
- Brotli
- br
- Zstandard
- zstd
- Content-Encoding
- Accept-Encoding
description: '介绍 Brotli 与 Zstandard 的内容编码与协商,Content-Encoding: br/zstd 的使用、服务器/CDN
配置与兼容注意,并提供参考与示例。'
categories:
- 文章资讯
- 编程技术
---
概述
Brotli(br)与 Zstandard(zstd)提供更高效的压缩,浏览器通过 Accept-Encoding 与服务器协商,返回对应 Content-Encoding。需正确设置压缩级别、变体缓存与 MIME。
示例:响应头与配置
Accept-Encoding: br, gzip, deflate, zstd
Content-Encoding: br
gzip off;
brotli on;
brotli_types text/html text/css application/javascript application/json;
# 若支持 zstd,可配置相应模块/反代(依赖环境)
工程建议
- 选择与回退:优先
br;在边缘/代理支持时考虑zstd;保持gzip作为广泛回退。 - 变体与缓存:基于
Accept-Encoding维度管理缓存;避免混淆不同编码。 - 压缩级别:平衡压缩率与 CPU;对静态资源使用预压缩文件。
参考与验证
- RFC 7932 Brotli 数据格式:https://www.rfc-editor.org/rfc/rfc7932
- RFC 8478 Zstandard 与
zstdContent-Encoding:https://www.rfc-editor.org/rfc/rfc8478 - MDN Content-Encoding 文档:https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Encoding

发表评论 取消回复