If thumbnails are made by a script each time a page is viewed, create each size once when the image is uploaded and serve it as an ordinary file. Start by checking the images' addresses.

A gallery that sits blank

The about page and the contact page of a small business site appear almost at once. The gallery page, with its slider and grid of photos, sits white for several seconds before anything shows.

It happens at the office and on a phone, at nine in the morning and at midnight. Visitors who wanted to see the work give up before the first photo arrives.

The photos are not unusually large on screen. The delay comes from how each thumbnail is made before it is sent.

How the theme makes its thumbnails

Many themes, especially those with sliders and portfolio grids, do not store small copies of each photo. Instead, every thumbnail's address points to a resizing script, with the original image and the size wanted written into the address.

When a browser asks for the thumbnail, the script opens the full-size original, shrinks it to the requested width and height, and sends the result.

The script is meant to save each result in a cache folder, so later visitors get the saved copy. When that works, only the first visitor waits.

Why the saved copies go unused

On slow galleries, the cache usually fails in one of these ways:

The first is the most common, and nothing announces it. The script simply resizes again, every time, and the page still works, only slowly.

What each visit asks of the server

A gallery page with twenty thumbnails starts the script twenty times. Each run loads a camera original, often several thousand pixels wide, into memory and shrinks it.

On shared hosting, where memory and processor time are limited per account, those runs queue behind one another. The slider at the top waits for its images, and the page waits for the slider.

Two visitors at once mean forty runs, and a search engine crawling the gallery adds its own.

Recognising it from the address

Open a thumbnail on its own, in a new tab, and look at its address. A saved file ends in something like photo-300x200.jpg.

An image resized on request shows a script name and a question mark, followed by the original file and a width and height. That image is being made by the server, possibly again for each visit.

The browser's developer tools show the same thing as timing: each thumbnail waits a second or more before its first byte arrives, while ordinary files start at once.

A worked example

In Duncan, an accordion repair shop rebuilds bellows, replaces reeds and tunes instruments, and its website shows each restoration in a gallery: the accordion as it arrived, during the work, and finished.

The gallery page had grown slow over the summer. The theme resized every photo through a script, and after a move to a new host in June its cache folder could no longer be written to.

Each visit opened dozens of camera originals. Customers mentioned the delay on the phone, asking whether the site was down.

The theme was changed to use sizes made at upload, the existing photos were processed once to create those sizes, and new photos are now reduced to a sensible width before they are uploaded.

A customer opening the restorations is sent small files the server already holds, so no photo waits for a script to shrink a camera original first.

Making each size once, at upload

WordPress, for example, creates a thumbnail, a medium and a large copy of every photo when it is uploaded, plus any sizes the theme registers.

The resizing happens once, while the person uploading is waiting anyway. Every visitor afterwards receives files that already exist.

A theme built properly asks for the sizes it needs and uses them. One that calls a resizing script on every page view can be changed to do the same.

Thumbnails as ordinary files

An ordinary image file is the cheapest thing a web server sends. It reads the file from disk and hands it over, without starting a script or opening a large original.

With nothing to compute, the server answers each image request at once, however many visitors arrive together.

The server can also tell browsers to keep image files for weeks, so a returning visitor's browser shows the gallery from its own copy instead of asking again.

Sensible originals

Photos straight from a camera are often 4,000 pixels wide or more. Even with sizes made at upload, those originals fill the server and slow every upload.

Reduce each photo to the largest size the site ever shows, such as 1,600 pixels wide, before uploading it. Keep the full camera files on your own computer or backup drive.

The counter-case

A resizing script with a working cache is not a disaster. If the gallery loads quickly, the cache folder is writable and the addresses stay the same, the first visitor waits and everyone else gets saved copies.

For a small site with a dozen photos, rebuilding the theme's image handling may not be worth it while that holds. Check the cache after every server move, though, since that is when it usually breaks.

Some resizing scripts have also had security holes, so a theme that still relies on one needs updating like any other software.

Fixing the gallery page

  1. Open a thumbnail in a new tab and read its address.
  2. Time the gallery in the browser's developer tools.
  3. Check the cache folder exists and can be written to.
  4. Switch the theme to sizes made at upload.
  5. Create those sizes once for the existing photos.
  6. Reduce new photos to a sensible width before upload.
  7. Tell browsers to keep image files for weeks.

Step four is the lasting repair. A cache can be fixed today and broken by the next server move, while sizes made at upload do not depend on any folder staying writable.

Photo pages can also keep visitors waiting behind a spinning circle that holds everything back until every image has arrived, the problem behind a loading screen that hides a page already built.


Frequently asked questions

Why is only the gallery page slow?

Its thumbnails are often made by a resizing script each time they are requested, while plain pages send text and ordinary files the server already has.

How can I tell if thumbnails are resized on request?

Open one in a new tab. An address with a script name, a question mark and a width and height means the server makes the image when asked.

What is the cache folder for?

The resizing script is meant to save each result there, so only the first visitor waits. If it cannot write to the folder, every visitor waits.

Why does the cache stop working after a host move?

Folder permissions often change in a move, and the script may lose the right to save files. It keeps working, just slowly, so nothing obvious breaks.

Does WordPress create image sizes itself?

Yes. It makes a thumbnail, a medium and a large copy at upload, plus sizes the theme registers. A theme should use those instead of resizing on request.

How large should photos be before uploading?

No wider than the largest size the site shows, such as 1,600 pixels. Keep the full camera files on your own computer or backup drive.

West Coast Media Solutions Inc. provides web design, web development, hosting, digital marketing, and business consulting to organisations across Canada, drawing on more than twenty-five years in the field.

Gallery page slow to appear?

Show us the slow gallery page, and we will check how its thumbnails are made and what it would take to fix them.

Start a Conversation