All notes

Responsive Images Need a Budget for Size, Crop, and Priority

Deliver appropriate images without making mobile readers download desktop originals or lose essential detail.

English edition, edited for length. Read the complete Chinese original.

Consider a 390-pixel-wide mobile page that downloads a 4000-pixel original image. The browser scales it down for display. It looks normal, but the transfer and decoding costs have already been incurred. Responsive images address not merely whether CSS can scale an image, but which candidate resources the server supplies and how the browser chooses between them.

This article discusses the use of cover and body illustrations in public blog posts. Screenshots of products should retain readability and avoid the same strong cropping strategy used in landscape photos; the budget for visual assets should be determined based on the reader’s tasks.

sizes Describes Layout, Not Resource Width

<img
  src="/images/workspace-960.webp"
  srcset="/images/workspace-480.webp 480w, /images/workspace-960.webp 960w, /images/workspace-1600.webp 1600w"
  sizes="(max-width: 700px) 100vw, 70vw"
  width="1600"
  height="1000"
  alt="A laptop and code editor on a desk"
/>

srcset supplies candidate images, while sizes tells the browser the expected display width. The 70vw value above is appropriate only when it approximates the actual layout. If the image sits in a container with a fixed maximum width, describe that constraint accurately; otherwise the browser may select an unnecessarily large resource.

Pixel density significantly impacts the choice of images. High-density screens require higher resolutions to display clearly. Don’t expect every phone to choose the smallest image, and don’t rely on the results of a single network request to infer the behavior of all devices. Browsers may reuse previously cached larger resources, so it’s important to control caching during testing.

Assume the maximum width of the content container is 720 pixels, with 16 pixels allocated to each side of the phone, centered on the desktop. The display width on the phone is approximately the viewport minus 32 pixels, with a maximum of 720 for wide screens, rather than always being 70% of the viewport. The sizes should express this constraint, and then generate a limited set of candidate values for common display widths and pixel densities. Having more candidates does not necessarily lead to faster performance, and the cost of building and storing also increases with the number of variations.

If a transparent architecture diagram is readable on a light background but its lines disappear in a dark theme, increasing resolution will not fix it. First check whether its lines and text depend on a particular background. Then decide whether to supply an explicit background, generate theme variants, or use a controlled graphic whose colors can be adjusted. If variants change legend colors, keep categories and markers consistent. Selecting the correct resource does not prove that its information remains distinguishable.

Technical screenshots and photographs require different compression judgments. Heavy compression may blur screenshot text while a photograph remains useful at lower quality. Compare representative content rather than applying one quality setting across the entire site. If a code screenshot cannot remain readable on mobile, present the code in a copyable block and use the image only for necessary interface context. Sometimes the most effective optimization is changing the information’s presentation rather than finding a smaller format.

Maintaining consistent dimensions can prevent text from jumping.

width and height provide intrinsic proportions, allowing images to scale responsively using CSS. If using a background image, the container should have clear proportions or height constraints. Determining the height after loading will push the title and body text downwards, disrupting the reading position.

Consider higher loading priority for images that are genuinely critical above the fold, and lazy loading for illustrations below the fold. Do not give every image high priority: resource contention can delay critical fonts, CSS, and scripts. Nor should you lazy-load the main above-the-fold image and expect it to appear promptly.

Cropping is a part of information design.

Technical screenshots should normally preserve all important regions. object-fit: cover suits photographs that tolerate cropping, but it may cut off code lines, axes, or essential buttons in a screenshot. If screenshot text is too small, provide an enlarged version or recapture the relevant region instead of making readers zoom the entire page.

When images need to be presented differently on mobile and desktop, the picture element can be used to specify different content for each. The alt attribute should provide a text description of the image that is relevant to the surrounding content, and should not simply repeat “This is a picture.” If the image is purely decorative, an empty alt attribute should be used to prevent screen readers from reading irrelevant details.

The intrinsic size of the image should be consistent with the CSS proportions. If the desktop version uses a full screenshot and the mobile version uses a cropped version, they may have different aspect ratios. It is necessary to explicitly specify this in the picture or layout rules to avoid adjusting the aspect ratio only after the image is loaded. Before cropping, clearly mark any information in the image that should not be lost, such as error messages, coordinate axes, and important buttons. If these areas are cropped on the mobile version, the article will still be incomplete, no matter how small the resulting image is.

Alternative text should explain the essential point conveyed by the image. An interface screenshot can describe the states being compared rather than list every button. Put a complex architecture diagram’s full explanation in nearby prose, with alt text summarizing and pointing to it; stuffing hundreds of words into an attribute does not establish accessibility. Decorative photographs can have empty alt text, but a technical image used as evidence must not lose its descriptive information merely because a heading already exists.

Loading Failure Test:

  • Preserve Image Size: Ensure the page doesn’t collapse when images fail to load.
  • Maintain Readability: Allow users to understand the content through text, even if the images are not fully loaded.
  • Accessible Image Zoom: If images are zoomable, the controls must have clear, accessible names and keyboard navigation.
  • Avoid Mouse-Only Interaction: Do not only bind mouse clicks to images, as this would prevent keyboard users from viewing the details.
  • Budgeted Resources: The resources for zoomed images should be budgeted and not downloaded in full during the initial visit.

Assume a log screenshot contains ten lines of context, with the actual error being discussed in the third line. Option 1: Keep the entire screenshot, suitable for explaining the preceding and following states. Option 2: Crop to the area around the error, suitable for quickly locating the error on a mobile device. Option 3: Convert the log into code blocks and retain the screenshot link, suitable for copying and searching. No single option is best in all scenarios; the best approach depends on the specific needs of the article and which information must be visible simultaneously.

Compare the alternatives using the same reader task, such as identifying an error’s cause or finding a button, rather than asking which image looks prettier. Tests using synthetic tasks can reveal small text, cropping, and zoom-control problems, but must not be presented as invented real-user research results. Record conditions and observations without turning a few internal trials into universal conclusions. Judge clarity by task success; the byte budget is only one constraint.

If you retain the full screenshot, explain the region of interest and provide an enlarged original. If you crop it, identify omitted context. If you convert it to code, keep the text consistent with the screenshot. After editing the article, check versions, paths, and identifiers shown in its images: an old screenshot may still recommend an obsolete configuration. Images used as technical evidence have a content lifecycle; uploading them does not end their maintenance.

File naming and alternative information should be maintained for easy upkeep. Use meaningful resource identifiers, record the original files and generated variations, and avoid having authors manually modify dozens of compressed files. When deleting an article, verify that images are still referenced by other articles. Do not directly remove shared assets based solely on their directory location. Build tools can generate dependency relationships to help identify isolated files and missing resources, but source licenses still need to be manually recorded.

Finally, review the cost of repeating images on the homepage. Thumbnail images do not need to be the same size as the main image on the detail page, and it’s even more important to limit resources when multiple thumbnails are loaded simultaneously. Reusing the original image is convenient for authors, but it can make a single article index page larger than the entire main text. Define appropriate sizes and loading strategies for each display purpose, and the responsive image budget will transition from optimizing a single image to ensuring a complete reading experience.

The priority of elements on the first screen should be based on real key elements.

The main image on the homepage is often the largest content element, but the largest content element on an article page might be the title or the body text. Don’t automatically give all images high priority just because one is at the top. Measure the loading process for specific pages to confirm resource contention. If the hero image uses lazy loading, the browser may only initiate requests after the layout is complete; conversely, if all images are loaded immediately, it could delay the loading of critical styles and content resources.

Preloading must accurately match the actual candidates, otherwise the browser will first download the preloaded file and then download another file based on the srcset, which is wasteful. When using responsive preloading capabilities supported by the platform or framework, check the final request instead of just confirming the existence of the tag. Over-preloading can also download resources that users will not see, especially when the layout is different between mobile and desktop.

The images below the main text can be loaded lazily, but users who want to quickly jump to a specific section still need a clear placeholder. Using fixed proportions, concise alternative text, and appropriate caching can reduce the feeling of waiting. After the images have loaded, avoid pushing the reading position down, especially in long technical articles, as a single layout change can make it difficult for readers to understand the code context. Observing the scrolling reading process is easier than simply taking a screenshot of the first page, and it’s a better way to identify problems.

External images are not free to maintain

Remote image services can change, be rate-limited, or become unavailable. Building with a fixed source provides consistent results, but increases reliance on the build network. Loading at runtime is simpler, but delegates requests to a third party. When choosing a source, consider licensing, privacy, and caching policies.

Do not arbitrarily download or rehost assets to bypass an image service’s restrictions; confirm usage rights first. Set maximum dimensions and allowed sources on an image-conversion service so it cannot be abused to generate large numbers of costly variants.

During acceptance, verify the actual download width, readability of the text, and layout stability across multiple views. Use a slow network connection to observe placeholder images and alt text, and confirm that the page remains readable even when images fail to load. The conclusions should be based on real-world resources and measurements, rather than simply reporting that one image format is “more advanced” than another.

If the width, quality, and URL parameters are allowed at runtime, the attacker can generate a large number of different combinations. Limiting the width range, quality range, and allowed sources, and rejecting or normalizing unknown combinations, can be effective. Obtaining the original image requires checking for timeouts, maximum byte size, and response type, as well as verifying the redirected source. Simply checking the URL extension is not sufficient to confirm the image content, and it cannot prevent internal resource requests on the server.

Build-time optimization reduces runtime dependencies but increases publication time. Define what happens when a remote resource is unavailable: fail the build or use a verified cached copy. A missing image that supplies evidence may need to block publication, while a decorative image can use a permitted fallback. Do not automatically substitute an unrelated stock image, since that changes the article’s information. Preserve asset sources and licenses for later updates or removal.

Using resource addresses with version or hash information enables long-term caching. New images receive new addresses. If the fixed filename overwrites an existing file, you need to consider the browser and CDN’s cached versions. Upgrading image conversion algorithms can also change the output. The cache key should include the valid conversion version to prevent new rules from reading old files. Changes in versions affect both caching and build costs, which can be observed in deployment reports.

Creating a Replicable Candidate Experiment for a Technical Screenshot

Select a synthetic screenshot containing small body text, an error message, and one essential button. Define the reader’s task first: identify the error line and find its corresponding action. Generate a limited set of size candidates and compare them inside the actual article container rather than opening each at its original dimensions. Record CSS display width, device pixel density, selected candidate width, transferred bytes, and text readability. Results apply to this image and these conditions, not a universal optimal compression setting for all screenshots.

For the first comparison, change only width while holding encoding and quality constant. For the second, fix width and compare encoding strategies. Changing several parameters simultaneously makes it difficult to attribute lost readability when bytes decrease. Inspect thin strokes, punctuation, and digits: one blurred character in an error code may change a technical conclusion. Edge blur acceptable in a photograph may be unacceptable in terminal screenshots or database execution plans.

Browser caching can affect the selection of candidates. The initial visit and subsequent visits are treated separately. Using cached large images after shrinking the viewport does not necessarily indicate incorrect sizes; the candidate budget can only be determined under independent initial conditions. High-density devices require more pixels, but also have constraints on network and memory, so they cannot generate infinitely large sizes. Prioritize task readability as the minimum quality, and then choose smaller resources above that baseline.

The art direction must maintain consistent argumentation.

A full desktop screenshot shows the context before and after an error, while the mobile crop shows only the error line. If the article’s conclusion depends on configuration in the preceding line, the mobile version has removed evidence. When preparing art-directed variants, list information that must remain and background that can be cropped, ensuring that each version supports the same argument. Alternative text must match the displayed image rather than describing controls absent from its crop.

picture selects resources, but layout must also account for their different aspect ratios. If the mobile crop is taller, its placeholder must not retain the desktop ratio or the body will move after loading. Define stable containers at each breakpoint and check that long titles, loading failures, and zoom controls do not overlap. A fixed ratio establishes a stable starting point; it does not require every image to be cropped into the same shape.

When a small-screen task requires comparing two images, simply arranging them in two columns may make them difficult to read. Instead, they can be arranged vertically, preserving clear labels, and key differences can be repeated in the main text. If a toggle control is provided, readers should be able to easily identify the current version and the location of changes, without relying on animations to explain. Image optimization should prioritize the comparison task, rather than simply aiming to display more thumbnails on the first screen.

Enlargement Has Its Own Resource and Interaction Responsibilities

When readers click to view the original image, they can download higher-resolution resources on demand, rather than pre-loading all original images on the homepage. The current small image and stable controls are retained during loading, and after a failure, the user can choose to close or retry, preventing the page from getting stuck in a blank pop-up. Original images can be very large, and still require a maximum size and byte budget. High resolution does not equal unlimited resolution; in most cases, verified large images are sufficient when only identifying interface details.

The layer-based approach requires keyboard focus, closing actions, and focus return. For new tab viewing, it requires a valid link and a clear name. The choice between these two methods depends on the task and maintenance costs. Touch zoom should not be the only method; keyboard users should also be able to access the details. After loading an image, the original focus should not be taken away. After closing, the article position should be restored. Adding interaction to a zoomable image also means adding new failure scenarios and accessibility checks.

Resource URLs should not contain long-term access credentials. Screenshots of the internal interface are de-identified before uploading, and both the original image and the thumbnail are checked. It is not possible to only mask the version displayed on the page while providing the download address with complete private information. Image editing may retain metadata; before sharing, check necessary information and file properties. Screenshots of technical blogs often contain account information, paths, and data. Content security is another hard constraint beyond the budget.

How the Generation Pipeline Prevents Uncontrolled Variants

Define approved width sets for each use, with finite candidates for lists, article bodies, and enlarged views, instead of allowing every component to request arbitrary widths. Derive values from layout, and record the source image, conversion version, and outputs in the build manifest. Before adding a new display use, check whether existing candidates suffice. Unbounded variants increase build time, storage, and cache fragmentation, while making asset deletion harder to assess.

Quality settings also need finite, justified policies. Photographs, screenshots, and transparent graphics can use different presets, but authors should understand how to choose. Do not silently fall back to a potentially oversized original after conversion fails. For evidence-bearing images, explicitly block publication or use a verified previous version; decorative images may use permitted defaults. Define failure behavior so a service outage does not suddenly make mobile readers download every original.

After upgrading the conversion algorithm, compare the size, transparency, textual details, and color of representative assets. The output hash change gives the new resource a new cache identity, but does not prove that it is of higher quality. Before removing isolated variations, check if older articles and existing page versions still need to be maintained, based on a comprehensive list of references. Asset maintenance should not only focus on the latest homepage, as long-tail articles also belong to public content.

Budget for Scrolling and Section Jumps, Not Only the First Screen

A long-form article of fifteen minutes may contain multiple execution plans and architectural diagrams. Continuous scrolling and direct anchor jumping on a slow network will change the order in which images appear in the viewport. Observe whether lazy loading starts promptly, whether placeholders maintain the reading position, and whether multiple image requests are consuming critical resources. Screenshots of the first page cannot reveal these paths; a real reading experience is required.

Record whether a task is achievable, the stability of the content position, and the actual download cost, keeping all three visible. If a low-byte result is unclear, it’s not successful; if a clear original image is downloaded every time, it’s not a reasonable budget. Through specific tasks, limited candidates, and failure experiences, continuous checks are formed, and responsive images truly serve technical content.

Separate records for four types of results

Record four outcomes separately: transfer results cover downloaded bytes and candidate width; presentation results cover the clarity of essential text; stability results cover position changes before and after loading; failure results cover whether the page remains understandable without the image. Halving file size does not establish that a technical screenshot is acceptable. Even a page without layout shifts may reserve so much space that it creates a large gap in the reading flow. Evaluate these results together.

The testing should cover at least narrow, wide, and high-density screen sizes, using real layouts instead of isolated image components. Control the initial visit cache and also test revisit reuse. Observe the first screen loading and skipping sections, and check if the text complements are complete when images are disabled. To compare the results before and after adjustments, it is necessary to clearly state the measurement methods and sample data. Do not draw the conclusion that all mobile users will be faster based on a single desktop browsing experience.

References: Responsive Images, Astro Images Guide.