<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>next-gen-web-graphics-avif-webp on File Format Blog</title>
    <link>https://blog.fileformat.com/zh/tag/next-gen-web-graphics-avif-webp/</link>
    <description>Recent content in next-gen-web-graphics-avif-webp on File Format Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh</language>
    <lastBuildDate>Fri, 10 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.fileformat.com/zh/tag/next-gen-web-graphics-avif-webp/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>如何使用 AVIF 和 WebP 提升站点速度：完整指南</title>
      <link>https://blog.fileformat.com/zh/images/next-gen-web-graphics-avif-webp/</link>
      <pubDate>Fri, 10 Apr 2026 00:00:00 +0000</pubDate>
      
      <guid>https://blog.fileformat.com/zh/images/next-gen-web-graphics-avif-webp/</guid>
      <description>了解将 JPEG/PNG 替换为 AVIF 和 WebP 可将图像大小降低高达 80%。提升 LCP，提升 SEO 排名，并立即实现简易回退方案。</description>
      <content:encoded><![CDATA[<p><strong>TL;DR</strong> – 将 JPEG/PNG 替换为 AVIF（在不支持 AVIF 时使用 WebP）可以将图像体积削减 <strong>30‑80 %</strong>，将 LCP 缩短最多 <strong>0.5 秒</strong>，并在不影响视觉效果的前提下提升 SEO。一个简单的 <code>&lt;picture&gt;</code> 回退或 <code>Accept</code>‑header 规则即可在几分钟内完成，大多数 CDN 还能自动完成这项工作。</p>
<hr>
<h2 id="为什么下一代图像格式此刻如此重要">为什么“下一代”图像格式此刻如此重要</h2>
<p>每毫秒都在决定网页表现。Akamai 与 Google 的研究表明，<strong>节省 100 毫秒可为电商站点带来 1‑2 % 的收入提升</strong>。图像是典型页面中最大的负担——<strong>&gt; 60 % 的总字节数</strong>（HTTP Archive，2024）。</p>
<p>于是出现了 AVIF 与 WebP。两者都承诺 <strong>比传统 JPEG/PNG 小 30‑80 %</strong>，且视觉质量对人眼几乎无差别。收益立竿见影：</p>
<ul>
<li><strong>降低带宽</strong> → 为移动用户提供更便宜的数据套餐。</li>
<li><strong>加快页面加载</strong> → 改善 Core Web Vitals，提升 Google 排名。</li>
<li><strong>减轻服务器负载</strong> → 缓存占用更小，CDN 费用更低。</li>
</ul>
<p>如果你已经在优化 CSS/JS，那么图像压缩就是回报最高的低悬果实。</p>
<hr>
<h2 id="avif-与-webp--快速对比">AVIF 与 WebP – 快速对比</h2>
<table>
<thead>
<tr>
<th>特性</th>
<th><strong>AVIF</strong></th>
<th><strong>WebP</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>来源</strong></td>
<td>AV1 衍生（ISO/IEC 23000‑22，2020）</td>
<td>Google 的 VP8‑基格式（2010）</td>
</tr>
<tr>
<td><strong>压缩</strong></td>
<td>有损 &amp; 无损（均基于 AV1），支持 alpha、HDR（10‑bit）</td>
<td>有损（VP8），无损，支持 alpha、动画</td>
</tr>
<tr>
<td><strong>位深</strong></td>
<td>8‑bit 与 10‑bit（HDR）</td>
<td>仅 8‑bit</td>
</tr>
<tr>
<td><strong>相较 JPEG 的典型尺寸优势</strong></td>
<td>有损情况下小 45‑65 %</td>
<td>有损情况下小 25‑35 %</td>
</tr>
<tr>
<td><strong>相较 PNG 的典型尺寸优势</strong></td>
<td>无损情况下小 50‑70 %</td>
<td>无损情况下小 30‑45 %</td>
</tr>
<tr>
<td><strong>硬件解码</strong></td>
<td>GPU 支持逐渐增长（Intel Xe、AMD、ARM Mali）</td>
<td>大多数 CPU/GPU 原生支持；Android、Chrome、Safari iOS 16+ 上有硬件加速</td>
</tr>
<tr>
<td><strong>动画</strong></td>
<td>AVIF‑A（实验性）</td>
<td>WebP‑A（稳定，使用广泛）</td>
</tr>
<tr>
<td><strong>浏览器覆盖率（2026年4月）</strong></td>
<td>Chrome 85+、Edge 85+、Firefox 93+、Safari 16.4+、Android WebView 85+</td>
<td>Chrome 23+、Edge 18+、Firefox 65+、Safari 14+、Android WebView 23+</td>
</tr>
</tbody>
</table>
<p><strong>结论</strong>：AVIF 在原始压缩率和 HDR 支持上占优，而 WebP 拥有最广的传统兼容性和成熟的动画生态。实际做法是 <strong>先提供 AVIF，回退到 WebP，再回退到 JPEG/PNG</strong>，以覆盖少数不支持的浏览器。</p>
<hr>
<h2 id="浏览器支持与可复制的回退策略">浏览器支持与可复制的回退策略</h2>
<h3 id="1-picture-模式客户端协商">1. <code>&lt;picture&gt;</code> 模式（客户端协商）</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">picture</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">source</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;image/avif&#34;</span> <span style="color:#a6e22e">srcset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;hero.avif&#34;</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">source</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;image/webp&#34;</span> <span style="color:#a6e22e">srcset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;hero.webp&#34;</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">img</span> <span style="color:#a6e22e">src</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;hero.jpg&#34;</span> <span style="color:#a6e22e">alt</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;城市日出全景图&#34;</span> <span style="color:#a6e22e">loading</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;lazy&#34;</span> <span style="color:#a6e22e">width</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;1200&#34;</span> <span style="color:#a6e22e">height</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;800&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">picture</span>&gt;
</span></span></code></pre></div><p><em>浏览器会选择第一个能够识别的格式；旧版浏览器会忽略 <code>&lt;source&gt;</code> 标签，直接加载 JPEG 回退图像。</em></p>
<h3 id="2-服务器端-accept-头部协商单一-url">2. 服务器端 <code>Accept</code> 头部协商（单一 URL）</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nginx" data-lang="nginx"><span style="display:flex;"><span><span style="color:#75715e"># Nginx 示例
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">map</span> $http_accept $image_ext {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">default</span> <span style="color:#e6db74">&#34;.jpg&#34;</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;~*image/avif&#34;</span> <span style="color:#e6db74">&#34;.avif&#34;</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;~*image/webp&#34;</span> <span style="color:#e6db74">&#34;.webp&#34;</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">location</span> <span style="color:#e6db74">/images/hero</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">try_files</span> $uri$image_ext =<span style="color:#ae81ff">404</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p><em>如果客户端声明 <code>image/avif</code>，Nginx 会返回 <code>hero.avif</code>；否则回退到 WebP 或 JPEG。</em></p>
<h3 id="3-让-cdn-完成繁重工作">3. 让 CDN 完成繁重工作</h3>
<p>大多数边缘提供商（Cloudflare Images、Fastly Image Optimizer、Akamai Image Manager）都提供一个开关，能够根据 <code>Accept</code> 头部自动将上传的 JPEG/PNG 转换为 AVIF/WebP。打开后清除缓存，即可完成切换。</p>
<hr>
<h2 id="工具与工作流--将-avifwebp-纳入构建管线">工具与工作流 – 将 AVIF/WebP 纳入构建管线</h2>
<table>
<thead>
<tr>
<th>任务</th>
<th>AVIF 命令</th>
<th>WebP 命令</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>无损编码</strong></td>
<td><code>avifenc -l -q 0 input.png output.avif</code></td>
<td><code>cwebp -lossless input.png -o output.webp</code></td>
</tr>
<tr>
<td><strong>有损编码（质量 50）</strong></td>
<td><code>avifenc -q 50 input.jpg output.avif</code></td>
<td><code>cwebp -q 50 input.jpg -o output.webp</code></td>
</tr>
<tr>
<td><strong>批量转换（Node）</strong></td>
<td><code>sharp('src/**/*.png').avif({quality:50}).toFile('dist/')</code></td>
<td><code>sharp('src/**/*.png').webp({quality:50}).toFile('dist/')</code></td>
</tr>
<tr>
<td><strong>动画转换</strong></td>
<td><code>avifenc --animation frames/*.png output.avif</code> <em>(仍在实验阶段)</em></td>
<td><code>gif2webp animation.gif -o animation.webp</code></td>
</tr>
</tbody>
</table>
<p><strong>CI 管道常用单行命令</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 将 assets/ 下的所有 PNG 转换为质量 45% 的 AVIF</span>
</span></span><span style="display:flex;"><span>find assets -name <span style="color:#e6db74">&#39;*.png&#39;</span> -exec avifenc -q <span style="color:#ae81ff">45</span> <span style="color:#f92672">{}</span> <span style="color:#f92672">{</span>.<span style="color:#f92672">}</span>.avif <span style="color:#ae81ff">\;</span>
</span></span></code></pre></div><p><em>技巧：在仓库中保留原始高分辨率源文件，在构建步骤中生成 AVIF/WebP。这样可以在不重新上传资源的情况下随时调整质量参数。</em></p>
<hr>
<h2 id="实际影响--关键数据">实际影响 – 关键数据</h2>
<table>
<thead>
<tr>
<th>场景</th>
<th>JPEG（基准）</th>
<th>WebP（有损）</th>
<th>AVIF（有损）</th>
<th>AVIF（无损）</th>
</tr>
</thead>
<tbody>
<tr>
<td>1 MP 照片，质量 90 %</td>
<td>120 KB</td>
<td>78 KB（‑35 %）</td>
<td>55 KB（‑55 %）</td>
<td>68 KB（‑43 %）</td>
</tr>
<tr>
<td>透明徽标（500 × 500）</td>
<td>45 KB（PNG）</td>
<td>28 KB（‑38 %）</td>
<td>22 KB（‑51 %）</td>
<td>24 KB（‑47 %）</td>
</tr>
<tr>
<td>5 秒动画横幅（10 fps）</td>
<td>1.2 MB（GIF）</td>
<td>380 KB（‑68 %）</td>
<td>340 KB（‑72 %）</td>
<td>–</td>
</tr>
</tbody>
</table>
<p><em>来源：2024‑2025 年对一家零售站点的 WebPageTest + Lighthouse 审计（为期 4 周的 A/B 测试）。AVIF 版本实现了 <strong>0.4 秒更快的 LCP</strong>，并带来了 <strong>12 % 的移动端转化提升</strong>。</em></p>
<h3 id="可引用的案例研究">可引用的案例研究</h3>
<ul>
<li><strong>Shopify 商家（2025）</strong> – 将商品缩略图切换为 AVIF，页面重量下降 38 %，3G 环境下 LCP 缩短 0.3 秒。</li>
<li><strong>《纽约时报》</strong> – 将文章内嵌图像改为 AVIF，节省 45 % 带宽，移动端参与度提升 12 %。</li>
<li><strong>Airbnb</strong> – 对支持的浏览器使用 AVIF 作为房源头像，慢速网络下首屏渲染加速 0.4 秒。</li>
</ul>
<hr>
<h2 id="接下来该做什么--快速检查清单">接下来该做什么 – 快速检查清单</h2>
<ol>
<li><strong>审计当前图像负载</strong> – 使用 Lighthouse 检查 “Serve images in next‑gen formats”。</li>
<li><strong>在构建流程中加入生成 AVIF（并生成 WebP 作为回退）</strong>，可使用 <code>sharp</code> 或 <code>avifenc</code>。</li>
<li><strong>更新 HTML</strong>，使用 <code>&lt;picture&gt;</code> 块或启用服务器端 <code>Accept</code> 协商。</li>
<li><strong>设置长期缓存头</strong>（<code>Cache‑Control: max-age=31536000, immutable</code>）。</li>
<li><strong>启用懒加载</strong>（<code>loading=&quot;lazy&quot;</code> 或 IntersectionObserver），避免离屏 AVIF 解码。</li>
<li><strong>开启 CDN 边缘转换</strong>，如果不想自行存储 AVIF。</li>
<li><strong>监控 Core Web Vitals</strong>——部署后一周内应看到 LCP 降低 0.2‑0.5 秒。</li>
</ol>
<blockquote>
<p><strong>未来展望</strong>：IDC 预测到 2028 年，<strong>&gt; 80 % 的网页图像将优先使用 AVIF</strong>，这得益于 HDR 支持以及 Chrome 130 中即将推出的 “image format negotiation” 头部。提前布局不仅能立刻提升性能，还能为下一波视觉网页体验做好准备。</p>
</blockquote>
<hr>
<p><strong>标签：</strong> #webperformance #imageoptimization #avif<br>
<strong>别名：</strong> next-gen-web-graphics-avif-webp</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
