Don't create two thumbnails of different resolutions for a single image
|Assignee:||Go MAEDA||% Done:|
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
srcsetattribute. The low-resolution thumbnail specified by
srcattribute is unnecessary for those browsers to render a page
- Even if a user's browser does not support
srcsetattribute, 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.