Patch #37597

Don't create two thumbnails of different resolutions for a single image

Added by Go MAEDA about 1 month ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Attachments
Target version:5.1.0

Description

Currently, Redmine creates two thumbnail images for each image. This is because the img tag for displaying thumbnails requires two resolution images (see below). For example, if Setting.thumbnails_size is set to 100, a 100px thumbnail and a higher resolution version of a 200px thumbnail will be created.

<img srcset="/attachments/thumbnail/24/200 2x" style="max-width: 100px; max-height: 100px;" loading="lazy" src="/attachments/thumbnail/24" />

However, a low-resolution 100px thumbnail is unnecessary for the following reasons:

  • Nowadays, almost all web browsers support srcset attribute. The low-resolution thumbnail specified by src attribute is unnecessary for those browsers to render a page
  • Even if a user's browser does not support srcset attribute, low-resolution thumbnails are still unnecessary. Since max-width and max-hight are specified, thumbnails are displayed at the expected size even with high-resolution images

The attached patch changes ApplicationHelper#thumbnail_tag to only use a high-resolution thumbnail only.

<img srcset="/attachments/thumbnail/24/200 2x" style="max-width: 100px; max-height: 100px;" loading="lazy" src="/attachments/thumbnail/24/200" />

This reduces the number of thumbnails created when a user accesses an issue or wiki page by half. This means that halves the number of calls of an expensive Redmine::Thumbnail.generate method.

generate-hires-thumbnails-only.patch Magnifier (1.36 KB) Go MAEDA, 2022-08-23 08:21

Associated revisions

Revision 21784
Added by Go MAEDA about 1 month ago

Don't create two thumbnails of different resolutions for a single image (#37597).

Patch by Go MAEDA.

History

#1 Updated by Go MAEDA about 1 month ago

Sorry I must have been mistaken. Browsers that support srcset never GET the image specified by src attribute. But the patch is still useful because it ensures that two different sizes of thumbnails are never created.

#2 Updated by Go MAEDA about 1 month ago

  • Subject changed from Halves the load of thumbnails creation to Don't create two thumbnails of different resolutions for a single image

#3 Updated by Go MAEDA about 1 month ago

  • Target version set to 5.1.0

Setting the target version to 5.1.0.

#4 Updated by Go MAEDA about 1 month ago

  • Category changed from Performance to Attachments

#5 Updated by Go MAEDA about 1 month ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch.

Also available in: Atom PDF