How to Test Responsive Image srcset URLs Before a Site Update

Learn how to test responsive image srcset URLs across viewport widths and device pixel ratios, and diagnose broken candidates, redirects, and layout issues.

Published
Reading time
9 min read
How to Test Responsive Image srcset URLs Before a Site Update
On this page

A product image can look correct on a desktop preview while failing on a phone: the browser may request a different URL at each viewport width and device pixel ratio. To test responsive image srcset URLs before a site update, check both the candidate URLs and the requests browsers actually select.

This workflow is for a staging site with representative product pages. It covers candidate selection, DevTools checks, broken URLs, redirects, and the difference between an image request failure and a layout problem.

Key Takeaways

  • With width descriptors such as 800w, sizes tells the browser the expected rendered width; the browser combines that information with display density and other factors to select a candidate.
  • Check multiple viewport widths and device pixel ratios. A URL that is never selected on your laptop may be selected on a phone.
  • Inspect currentSrc and the Network panel together: one identifies the selected URL, while the other helps explain what happened to its request.
  • Verify every candidate URL and its actual image dimensions, not just the candidates selected during a small viewport test.
  • A successful image request does not prove the image is sized, cropped, or positioned correctly on the page.

How browsers select a srcset candidate

Consider this illustrative markup for a product card:

<img
  src="/images/blue-chair-800.jpg"
  srcset="/images/blue-chair-400.jpg 400w,
          /images/blue-chair-800.jpg 800w,
          /images/blue-chair-1600.jpg 1600w"
  sizes="(max-width: 600px) calc(100vw - 32px),
         calc(50vw - 48px)"
  alt="Blue upholstered chair"
>

The w descriptors state the intrinsic widths of the image resources in pixels. The sizes attribute describes the expected display width of the image in CSS pixels: here, nearly the full viewport on small screens and roughly half the viewport on larger screens. These values must reflect the actual layout; they do not set the image's CSS width themselves.

The browser uses the applicable sizes value, available candidates, device pixel ratio (DPR), and potentially other factors to select a resource. For example, a slot about 400 CSS pixels wide on a DPR 2 display suggests a resource around 800 image pixels wide. This is a guide, not a promise that a particular candidate will always be chosen.

A srcset can instead use density descriptors such as 1x and 2x. In that case, the descriptors express pixel density rather than resource width; sizes is relevant to width-descriptor selection, not that density-descriptor calculation. A <picture> element adds another step: the browser first selects an applicable <source> based on its conditions and supported type, then selects a candidate from it. Inspect that source as well as the fallback <img>.

The HTML Living Standard defines responsive image selection, and browser documentation explains the available developer tools. Neither source was available to consult for this article, so check the standard and your target browser's current documentation for version-specific behavior and DevTools controls.

Advertisement

Prepare a staging test matrix

Choose pages that exercise different image sources and layouts, rather than testing just one product:

  • A typical product detail page and a category or product listing page.
  • Products with different aspect ratios, multiple gallery images, and images recently added or replaced in the catalog.
  • Pages using different image templates, formats, CDNs, or <picture> sources.
  • Relevant sale, variant, or locale pages if they generate different image URLs.

For each representative image, check a small viewport, a medium viewport, and a wide desktop viewport. Include widths just below and above every breakpoint used by the image layout, sizes, or <source media>. Repeat at DPR 1 and DPR 2 where supported, and include other densities used by your target devices.

Record the page, viewport width in CSS pixels, DPR, selected URL, request result, and visible result. Use the same staging build and catalog data for each pass. A viewport width alone is not enough: two devices with the same CSS width but different DPRs can select different candidates.

Check selected image requests in DevTools

The exact control names vary by browser and version. In a browser's developer tools, use this repeatable process:

  1. Open the staging page and turn on responsive or device emulation. Set a viewport width and, if the tool offers it, a DPR. Otherwise, use a suitable real device or browser environment. Keep page zoom consistent and record the actual values.

  2. Open the Network panel before reloading. Filter for images and enable the option to disable cache while DevTools is open, if available. Reload so you can see the initial image requests.

  3. Select the product image in the Elements or Inspector panel. Check the <img> attributes and, if present, its enclosing <picture> and <source> elements.

  4. In the console, with the image selected as $0 in a DevTools implementation that supports it, inspect the selected URL and display context:

    const img = $0;
    console.log({
      viewportWidth: window.innerWidth,
      devicePixelRatio: window.devicePixelRatio,
      renderedWidth: img.getBoundingClientRect().width,
      currentSrc: img.currentSrc,
      complete: img.complete,
      naturalWidth: img.naturalWidth
    });
    

    If your DevTools does not provide $0, select the image by a suitable page-specific selector instead. Run the snippet after the image has had time to load. complete alone is not proof of success: it can also be true for a broken image. A zero naturalWidth is a useful failure signal, but use the Network panel and rendered page to investigate. Do not use naturalWidth alone to verify the source file's pixel width; browser-reported intrinsic dimensions can be density-corrected.

  5. Find the currentSrc URL in Network. Inspect its status, redirect chain if shown, response details, and any browser error. Confirm that the image visibly renders in the intended slot.

  6. Change width or DPR, reload, and repeat. Browsers may reuse a previously loaded resource during resizing, so a fresh reload with cache disabled is useful for a consistent initial-load check. Some images may be lazy-loaded; scroll them into view before judging whether a request is missing.

The console snippet is a diagnostic aid, not a complete test suite. It was not executed for this article. Avoid pasting sensitive signed image URLs into public bug reports or external tools.

Validate every candidate, including hidden failures

Viewport testing shows what was selected under the conditions you tried; it does not guarantee that every declared candidate works. Inspect the markup or generated catalog data and make an inventory of each src, srcset, and <source srcset> URL for the representative pages.

For each candidate:

  1. Resolve relative paths against the page's base URL and check that the URL points to the intended staging asset. Look for stale filenames, case differences, missing variants, and incorrect query parameters.
  2. Request the URL in the same authenticated staging context when necessary. Confirm that the response is the intended image and that it decodes, not merely that the server returned a success status. An HTML error page returned with a success status is still a broken image.
  3. Compare each w descriptor with the actual pixel width of its corresponding image file using an image metadata inspector. A file declared as 1600w must actually be 1600 pixels wide. Incorrect descriptors can cause the browser to choose a resource that is too small or unnecessarily large.
  4. Inspect redirects through to the final response. Confirm the final destination is expected, accessible in the relevant environment, and returns the intended image. Check for loops, expired signed URLs, and redirects to login or error pages.
  5. Check candidates declared only in a particular <source> or layout breakpoint. Test just below and above that condition, then verify the selected URL in DevTools.

Opening a candidate directly can help identify a bad URL, but it is not a substitute for loading it in the page. Authentication, referrer restrictions, mixed-content blocking, content security policy, and browser caching can make the page request behave differently. A failed selected candidate should not be assumed to fall back automatically to another srcset URL; fix the failing resource or markup.

Advertisement

Separate request failures from layout problems

Use the selected URL and Network result to decide where to investigate next:

SymptomWhat to check
No image request appearsConfirm the correct source is applicable, the image has entered the viewport if lazy-loaded, and the Network panel was recording during reload. Inspect console errors and blocking policies.
Request fails or redirects unexpectedlyCheck the URL, response, final destination, authorization, signed-URL lifetime, and browser error. Retest in the page after fixing it.
Request succeeds but image is brokenInspect response content and decoding; a success status does not establish that the body is a valid image.
Image loads but is blurryCompare rendered width and DPR with the selected resource, then check actual file dimensions, descriptors, and whether sizes understates the slot. Also inspect the source asset's quality.
Image loads but is cropped, stretched, or misplacedInspect the container dimensions, CSS sizing, aspect ratio, and properties such as object-fit and object-position. A working URL does not establish correct layout.

When the image is wrong, check that the selected resource belongs to the intended product or variant as well as whether it loads. Catalog updates can produce valid URLs that point to the wrong image.

Common Mistakes

  • Testing only one viewport or DPR. This misses candidates selected on other screens and near breakpoint boundaries.
  • Assuming sizes controls layout. CSS determines the rendered slot; sizes describes that slot for candidate selection. Update both when a redesign changes the layout.
  • Trusting filenames as dimensions. Check image metadata against each width descriptor, especially after automated image transformations.
  • Treating an HTTP success as a complete pass. The response can contain the wrong asset, invalid image data, or an error page.
  • Checking only the final redirect target. An intermediate redirect can fail or behave differently for the page request.
  • Interpreting a layout defect as a broken URL. Confirm the request and decoded image before changing the image pipeline.

Best Practices

Before release, retain the test matrix and attach the selected URL, viewport, DPR, network result, and screenshot to each issue. Recheck affected representative pages after fixing templates, CSS, image transformations, or catalog records; any of them can change which resource is selected or how it appears.

Where practical, add automated checks for generated candidate URLs, response validity, and descriptor-to-file-width agreement. Keep browser checks too: a URL inventory alone cannot verify the actual responsive layout or all browser request conditions. Use real target devices or browsers for a final pass when their rendering or selection matters to the release.

Conclusion

Test responsive images as both a set of asset URLs and a browser selection workflow. Combining candidate validation with viewport, DPR, Network, and visual checks makes breakpoint-specific failures easier to find before a site update.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.