用 picture + srcset 构建响应式图片管线
Responsive images have been a real pain point for years. You either served a too-large image to mobile users and wasted bandwidth, or cropped aggressively and lost visual quality on the desktop. The <picture> element with srcset and sizes fixes this — with one clean HTML 教程 declaration, the browser picks the right image for the user's device.
解决什么问题?
A single <img> can only serve one source. Every visitor gets the same bytes, regardless of screen size, pixel density, or connection speed. That means a 2× Retina display phone loads a 2× image even though its viewport is smaller than a desktop.
picture 元素
Wrap your fallback <img> in <picture>, then add <source> elements above it. Each source can specify media conditions, a sizes list, and srcset variants. The browser picks the first matching source it understands.
<picture>
<source media="(min-width: 1000px)"
srcset="wide.jpg 1x, wide-2x.jpg 2x">
<img src="fallback.jpg" alt="mountain">
</picture>
小结
Responsive images aren't optional anymore. Every image you put on a page should have a plan for different widths and densities. picture 元素 gives you clean, declarative control over what the browser loads — no JavaScript 教程, no external library, zero network guesswork.