Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34341 closed defect (bug) (fixed)

Limit the size of images included in srcset attributes

Reported by: joemcgill's profile joemcgill Owned by: joemcgill's profile joemcgill
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

Since #33641, all available intermediate sizes of an image that are the same aspect ratio will be included in the image's srcset attribute.

In some cases, this may cause users to download unnecessarily large images. For example, if the original image is using the large size in the src attribute and the only larger option available for retina devices is an uncompressed full-size image, a browser could end up downloading a very large file.

While we can't filter images based on the file size, we can set an upper limit on the width of images that are included in srcset attributes by default and allow theme authors to filter the value as needed.

Attachments (2)

34341.diff (1.1 KB) - added by joemcgill 9 years ago.
Add $max_srcset_width and default to 1600px
media-continue.diff (448 bytes) - added by aduth 9 years ago.
Correctly continue to filter images wider than filter value

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in Slack in #feature-respimg by joemcgill. View the logs.


9 years ago

#2 @joemcgill
9 years ago

  • Owner set to joemcgill
  • Status changed from new to accepted

@joemcgill
9 years ago

Add $max_srcset_width and default to 1600px

#3 @azaozz
9 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35358:

Responsive Images: limit the size of images included in srcset attributes. Introduce max_srcset_image_width filter to adjust the limit.

Props joemcgill.
Fixes #34341.

#4 @netweb
9 years ago

  • Milestone changed from Awaiting Review to 4.4

#5 follow-up: @aduth
9 years ago

@azaozz , I suspect there may be a typo in your r35358 - $contiue; should likely be continue;

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/media.php?rev=35358#L959

@aduth
9 years ago

Correctly continue to filter images wider than filter value

#6 @azaozz
9 years ago

In 35378:

Responsive Images: fix typo in r35358.

Props aduth.
See #34341.

#7 in reply to: ↑ 5 @azaozz
9 years ago

Replying to aduth:

Ugh, thought I fixed that from the "commit" dialog in Tortoisesvn, but it didn't get included in the current commit.

Note: See TracTickets for help on using tickets.