Skip to content
Insights

Lighter websites

Portfolio and Gallery Pages Without the Weight

Gallery and portfolio pages can send every full-size photo at once. Use small thumbnails, open big images on click and lazy-load the rest of the grid.

Sol Rudd6 min read

Diagram: a browser showing a grid of small photo thumbnails, with one selected; an arrow leads to a single enlarged photo labelled Full size on click

For a photographer, a furniture maker or a design agency, the gallery is the point of the website. It is also, often one of the heaviest pages on it. The usual reason isn't the number of pictures but how they are delivered: a grid of small squares that quietly downloads every photo at full size, all at once. This article covers three changes that keep the work looking its best while sending far less: properly sized thumbnails, full images that load when someone asks for them, and lazy loading for the rest of the grid.

Thumbnails should be thumbnail-sized

A thumbnail shown 300 pixels wide doesn't need a 4,000-pixel photo behind it. web.dev's image gallery guide puts it simply: you “likely don't want to show them the full resolution image, especially in the gallery of thumbnails”. It suggests resizing images before upload, or setting up the server to resize them for you. If your website system makes smaller copies when you upload, check that the gallery template actually uses them.

Screens differ, so a thumbnail can come in a few widths and let the browser choose. On the img element, srcset lists the available files and their widths, and sizes says how wide the image will appear in the layout. MDN notes that if sizes is left out it defaults to the full viewport width, so the browser assumes each thumbnail fills the screen and may choose a larger file than the grid square needs.

<img src="chair-400.jpg"
  srcset="chair-400.jpg 400w, chair-800.jpg 800w"
  sizes="(width <= 600px) 50vw, 300px"
  width="400" height="300" alt="Oak dining chair, side view">

MDN's responsive images guide gives a small worked example: an 800-pixel picture of 128 KB against a 480-pixel version of 63 KB. On a page of thirty images, savings like that add up. For choosing formats and compression, see image weight: the quickest win and image formats compared.

Full images on click, not on load

Visitors who want the detail will click. Everyone else only needs the grid. So the large version of each photo should load when someone opens it, not when the page opens. web.dev's gallery guide describes exactly this, “loading a larger image size when the user clicks on an image”, and recommends the native <dialog> element for the enlarged view, which it describes as Baseline widely available and needing less custom JavaScript. With lazy loading in place, it notes that an image initially hidden in a dialog “won't load until the dialog is opened”.

  • The plainest version: link each thumbnail to its large file or to a page for that project. The large image is opened only by those who click.
  • A lightbox: fine, as long as it fetches the large image when opened. If yours loads every full-size image in the background so the lightbox feels instant, the saving is lost; the check below shows which it does.
  • Project pages: for agencies, a short case-study page per project often works better than one long page holding every image of every project.

Lazy-load the rest of the grid

A long grid can still hold back the thumbnails nobody has scrolled to. Adding loading="lazy" to an image defers it, in MDN's words, “until it reaches a calculated distance from the viewport”. web.dev's lazy-loading guide says Chrome uses 1,250 pixels on fast connections and 2,500 pixels on slower ones, so images start loading a little before they come into view.

  • Leave the first row alone. web.dev advises: “Don't lazy-load images that are likely to be in-viewport when the page loads”. The first images people see should load straight away.
  • Give every image a width and height. web.dev warns that without dimensions, “the browser might decide that all of them fit inside the viewport” and load the whole gallery anyway. MDN adds that dimensions let the browser reserve space, so the grid doesn't jump as photos arrive.

What the carbon test sees

GreenTracer measures one first, uncached load of the page with Google PageSpeed Insights, on mobile and desktop, and uses the heavier run. The test does not scroll or click, but lazy loading works by distance, not by scrolling: web.dev explains that Chrome starts fetching a lazy image once it is within about 1,250 to 2,500 pixels of the screen. So the first few rows below the screen may still be counted, while thumbnails further down a long grid, and full-size images that wait for a click, usually are not. How many rows that means depends on the length of your gallery and the browser, so use the Network panel check below to see exactly which thumbnails load before you scroll.

That reflects a real difference, not a loophole: a visitor who glances at the first screen and leaves no longer downloads the whole portfolio. But someone who scrolls to the end still downloads every thumbnail, so small thumbnails matter as much as lazy loading. Under the Sustainable Web Design Model v4, each megabyte removed from the first load lowers the estimate by about 0.148 g CO₂e per page view (about 0.121 g on a host listed as green).

Check your gallery page

  1. Open the page in Chrome with DevTools' Network panel, tick “Disable cache” and choose the Img filter. Reload without scrolling and look at how many images load and how big they are.
  2. If a 300-pixel thumbnail shows a file of several hundred kilobytes, the template is using full-size files.
  3. Click one thumbnail. Exactly one large image should appear in the list.
  4. Check the page before and after the changes and compare the bytes measured.

Sources

All articles

Check your own site

See the estimated carbon of one page view on your page, its grade, and whether your host is listed as green. It's free.

Check a website