48 CZ-PRG (GMT+1)
US-NYC (GMT-5)
Blazor Web App (Server rendered)

A field guide to responsive image delivery

Dynamic
image resizing.

Keep one high-resolution original on the server. Resize it for the browser's needs when requested, choose cropping separately, and cache the result for the next visitor.

.NET 10 Blazor Server Bootstrap 5.3 328 2K+ originals
01THE TERMS ARE RELATED, NOT IDENTICAL

One source image.
Several useful responses.

Dynamic image resizing (also called on-the-fly resizing) means the server transforms an original while handling an image request. Depending on the selected processor, it can resize, crop, rotate, and re-encode the file before returning the response.

Responsive image delivery is the browser-facing part. HTML provides a set of candidate URLs with srcset and describes the rendered slot with sizes. The browser chooses a candidate for its layout and pixel density. The server then creates or retrieves that URL's variant.

01 / SOURCE

Keep a good original

Store the largest practical source once. Do not make a separate hand-exported file for every device width.

02 / REQUEST

Describe the variant

Put bounded transformation commands in the URL: width, an optional fit box or crop mode, output format, and quality. Exact crop commands differ between libraries.

03 / DELIVERY

Return fewer bytes

The browser receives the smaller encoded image—not the original followed by a CSS shrink.

Important distinction: CSS such as width: 100%, Bootstrap .img-fluid, and object-fit: cover change how an image is drawn. By themselves they do not reduce the bytes downloaded.

02WHAT HAPPENS IN THIS .NET APP

Razor renders the URL.
Middleware renders the image.

This site uses .NET 10, server-rendered Razor components, and the Interactive Server render mode. The component produces ordinary HTML; the ImageResize middleware handles each image as a separate HTTP request, outside the Blazor SignalR circuit.

01 / SOURCE

Original stays on disk

wwwroot/images/001/…jpg

2,752 × 1,536 px JPEG
02 / HTML

Razor writes candidates

srcset and sizes describe the image slot.

No image bytes in the component markup
03 / BROWSER

Browser picks a URL

Layout width × device pixel ratio informs the choice.

Native loading="lazy" defers off-screen files
04 / PIPELINE

ImageResize handles it

SkiaSharp middleware reads the source and fits it to the requested bounds.

Before the static-asset endpoint
05 / RESPONSE

Send and cache a variant

Return the encoded result with normal HTTP caching headers.

Later identical requests reuse cached output
ONE REAL IMAGE REQUESTHTTP GET
/images/001/01-01a-g.jpg?width=640&height=480&quality=88

The 2,752 × 1,536 JPEG is fit inside a 640 × 480 box, preserving its 16:9 aspect ratio, so the response is 640 × 357. ImageResize uses SkiaSharp's Mitchell cubic resampler; JPEG quality 88 controls encoding artifacts. The original stays unchanged and the first result is cached for later identical URLs. The card's 4:3 frame is cropped visually by CSS.

BLAZOR SERVER IS NOT A PROXY FOR THE IMAGE BYTES

The first HTML is rendered on the server. Once the browser parses it, it requests the image URL directly over HTTP. The resized JPEG response does not travel through the Blazor SignalR circuit. ImageResize is registered before this app's static-asset endpoints, reads from the images content root, and stores cached derivatives under App_Data/image-cache. Requests without resize parameters continue as original static assets.

The gallery component reads filenames, dimensions, and original file sizes on the server to render its cards. It does not read every image into SignalR or send the image data in a component event.

03RESPONSIVE LAYOUT / BOOTSTRAP 5.3

The viewport changes the slot.
The browser chooses the bytes.

The server does not magically know the viewport from a Razor component. The page publishes candidate image URLs, while sizes tells the browser approximately how wide the image will render at each Bootstrap breakpoint. These estimates account for the desktop navigation column, the page shell's maximum width and padding, and Bootstrap gutters.

BOOTSTRAP 5.3 GRIDGALLERY COLUMNSEXAMPLE VIEWPORT / SLOT2× DPR TARGET
XL and larger · ≥ 1,200 pxrow-cols-xl-41,440 px viewport · ≈248 CSS px≈496 source pixels
LG · 992–1,199 pxrow-cols-lg-31,024 px viewport · ≈211 CSS px≈422 source pixels
SM / MD · 576–991 pxrow-cols-sm-2768 px viewport · ≈209 CSS px≈418 source pixels
XS · below 576 pxrow-cols-1390 px viewport · ≈350 CSS px≈700 source pixels
HTML CONNECTS LAYOUT TO VARIANT URLSRESPONSIVE IMAGE
<img
  src="/images/001/01-01a-g.jpg?width=640&height=480&quality=88"
  srcset="/images/001/01-01a-g.jpg?width=320&height=240&quality=88 320w,
          /images/001/01-01a-g.jpg?width=640&height=480&quality=88 640w,
          /images/001/01-01a-g.jpg?width=960&height=720&quality=88 960w,
          /images/001/01-01a-g.jpg?width=1440&height=1080&quality=88 1440w"
  sizes="(min-width: 1840px) 332px, (min-width: 1818px) calc(378px - min(46px, 2.5vw)),
         (min-width: 1200px) calc(22.5vw - 76.5px), (min-width: 992px) calc(30vw - 96.67px),
         (min-width: 641px) calc(45vw - 137px), (min-width: 576px) calc(45vw - 8px),
         (min-width: 400px) 90vw, calc(100vw - 40px)"
  width="640" height="357" loading="lazy" decoding="async"
  alt="High-resolution source image 01-01a-g.jpg">

The width descriptor (for example 640w) must match the generated image width. The browser combines sizes, its device-pixel ratio, supported formats, and its own network heuristics to choose a candidate. Every candidate has the same fit and encoding commands, so it can safely switch widths when the viewport or zoom changes.

CSS SIZES THE FRAME

max-width: 100% prevents overflow.

It makes an image fit its container after the browser has a resource. It cannot retroactively make the original transfer smaller.

SERVER PARAMETERS SIZE THE FILE

width changes the response pixels.

Each selected URL can request an appropriately sized derivative. Fixed candidates also prevent a client from inventing unlimited URL variants through this page.

CROP IS A SEPARATE DECISION

object-fit: cover is visual.

The gallery requests a 16:9 fitted JPEG, then CSS crops it inside the Bootstrap 4:3 frame. The response still contains the side pixels hidden by cover. Use a server processor with a crop command when you want to avoid transferring pixels outside the visible composition.

Do not lazy-load the LCP image. This gallery is below the explanatory content, so its cards use loading="lazy". A prominent first-screen hero image should usually be eager (or explicitly prioritized) and should have its dimensions or aspect ratio reserved to avoid layout shift.

04THREE .NET MIDDLEWARE OPTIONS

Choose one handler
for a given image URL.

ImageResize 3.5.0 is active and Core5.ImageResizer 10.0.1 is installed as an alternative. ImageSharp.Web 3.3.0 / ImageSharp 3.2.0 are documented below, but not referenced: despite this repository's MIT license qualifying for the Apache 2.0 grant, the v3 package's build target still requires a valid Six Labors key for Release builds. It is not license-key-free. Run only one image middleware for a given URL path.

.NET 10 INSTALLED
LIVE GALLERY PROVIDERImageResize · 3.5.0ACTIVE · MIT

SkiaSharp-backed middleware with disk cache

The package targets .NET 10, decodes JPEG, PNG, WebP, GIF, BMP, and TIFF, and preserves the original format. This app's configuration monitors the images root, prevents upscaling, defaults to JPEG/WebP quality 88, caps dimensions at 1,440 × 1,080 and quality at 90, and limits its disk cache to 1 GB.

Version 3.5.0's SkiaSharp codec uses the Mitchell cubic resampler. Its URL does not expose a sampler switch: quality=88 changes JPEG/WebP encoding quality, not edge interpolation. Raising quality can reduce compression artifacts, but it cannot remove aliasing produced during resizing. ImageSharp.Web can select Lanczos3 if a valid Six Labors license key is configured for Release builds.

License: MIT. It is a distinct implementation from ImageSharp.Web, not a second layer to run on the same request.

INSTALL AND REGISTERPROGRAM.CS
dotnet add package ImageResize --version 3.5.0

using ImageResize.Core.Extensions;

var imageCacheRoot = Path.Combine(
    builder.Environment.ContentRootPath, "App_Data", "image-cache");
Directory.CreateDirectory(imageCacheRoot);

builder.Services.AddImageResize(options =>
{
    options.ContentRoots = ["images"];
    options.WebRoot = builder.Environment.WebRootPath;
    options.CacheRoot = imageCacheRoot;
    options.AllowUpscale = false;
    options.DefaultQuality = 88;
    options.Bounds.MaxWidth = 1440;
    options.Bounds.MaxHeight = 1080;
    options.Bounds.MaxQuality = 90;
    options.Cache.MaxCacheBytes = 1_073_741_824;
    options.Cache.PruneOnStartup = true;
});

app.UseImageResize();
app.MapStaticAssets();
RAZOR / FIT WITH ASPECT RATIO PRESERVEDCOMPONENT CODE
private static string ResizeUrl(string source, int width) =>
    $"{source}?width={width}&height={width * 3 / 4}&quality=88";

private static string SourceSet(string source) =>
    string.Join(", ", ResponsiveWidths.Select(width => $"{ResizeUrl(source, width)} {width}w"));

<img src="@ResizeUrl(image.Url, 640)"
     srcset="@SourceSet(image.Url)" sizes="@ImageSizes"
     width="640" height="357" loading="lazy"
     decoding="async" alt="@image.Alt" />
URL SHAPE/images/001/photo.jpg?width=640&height=480&quality=88
WHY THE TABS DO NOT SWITCH THE LIVE MIDDLEWARE

The tabs compare package setup and URL syntax; only the selected code sample changes. ImageResize is the middleware currently configured at startup. To run Core5 instead, change the server registration and URL builder, then verify its ordering against this app's static-asset endpoints. To run ImageSharp.Web, first provide a valid Six Labors license key/file for Release builds, add the packages, and replace the active middleware. Never run multiple image handlers on the same path.

06PRODUCTION NOTES / COST, CACHE & SAFETY

Fast after the first transform.
Still a server workload.

Resizing on demand trades storage duplication for CPU work on a cache miss. Good URL design, cache policy, and bounded parameters make that trade worthwhile.

01 / CACHE KEY

One URL, one representation

Width, crop, format, and quality all affect the result. A finite set of candidate URLs prevents needless cache variants; plan how to invalidate derivatives when a source changes.

02 / RESOURCE LIMITS

Bound dimensions and work

Do not trust arbitrary query values. Restrict source paths and formats, enforce maximum width/height/quality, prevent unwanted upscaling, and cap cache storage. For public transformation URLs, consider ImageSharp.Web HMAC signing so clients cannot freely invent costly variants.

03 / FIRST REQUEST

Decode, transform, encode

The first uncached request costs CPU and memory. Warm popular variants if needed; monitor cache misses and avoid decoding huge originals without an input-size limit.

04 / HTTP DELIVERY

Use browser and edge caching

ETags and cache-control help repeat visits. A CDN can cache the transformed URL near users, provided its cache key includes the transformation parameters.

05 / IMAGE QUALITY

Sampler and encoder quality are different

ImageResize uses SkiaSharp's Mitchell cubic sampler; this version does not expose a URL-level filter switch. JPEG quality=88 controls compression artifacts, not pixel interpolation, so it may improve blockiness but cannot change a jagged edge created during downsampling. ImageSharp.Web offers rsampler=lanczos3 and compand=true if a valid license key is available. Compare at the actual card size; stronger filters can create halos and cannot restore missing source detail.

06 / LONG GALLERIES

Lazy loading is a different lever

loading="lazy" delays off-screen requests; resizing reduces the bytes in each request. For thousands of records, also page or virtualize the rendered cards.

Good default: store originals privately or in a controlled source folder, publish a small set of responsive widths, decide whether to crop on the server or in CSS, cache each representation, and verify real response sizes in browser DevTools.

WEB DESIGN / PERFORMANCE & IMAGESServe the right image for the slot
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.