Image style 404 is not cacheable

Created on 4 March 2022, over 3 years ago
Updated 30 May 2025, 9 days ago

Problem/Motivation

If an image style request (/sites/default/files/styles/medium/public/2022-03/test-file.png?itok=12345) cannot find the file because it doesn't exist, the resulting 404 is not cacheable unlike other 404s on the site. When migrating from a Drupal site to a new Drupal site it can mean a large amount of resource generating 404 pages until the requests are binned before reaching Drupal or the sources updated to no longer point to a new location (since fast_404 excludes styles).

Steps to reproduce

1. Visit a made up style URL. Note the page is not cached by page_cache and not cacheable by a proxy and so the 404 generates every time

Proposed resolution

Note sure but I was curious if there was an explicit reason for this. Possibly DenyPrivateImageStyleDownload could be updated to only deny where the response was not a 404, which initially seems plausible. This allows the 404 to cache in page_cache as well as in proxy (and to be fair it's the proxy I personally want it to cache in). Happy to MR for this but wanted to avoid in case there's a reason it's like this.

Remaining tasks

-

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component

image system

Created by

🇬🇧United Kingdom Driskell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024