You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a "mini-proposal" on how to handle images in the editor and the front-end (follow-up from #4914).
Currently:
Images are inserted in the editor at full size, i.e. we force the user to download 2MB-5MB files in most cases.
When the user saves the post without changing image source from the inspector, it is possible that front-end visitors will have to also download the huge files. WP adds proper srcset attribute, but the sizes attribute is pretty useless as it only refers to the full size image file: sizes="(max-width: 6000px) 100vw, 6000px".
To fix this in the editor:
Always insert the "large" size (1024px) images . If it doesn't exist (if the uploaded image is smaller), insert the "full" size.
Add srcset attribute that will also list 2x large size (so images are retina ready). This is a new size and will have to be added to the default WP sizes, see below.
Add another attribute to the tag for Gutenberg images so we can recognize them easily in PHP. This is necessary as we will have to calculate the front-end srcset and sizes attributes a bit differently. Ideally that should have the attachment ID, something like data-wp-attachment-id="1234". Then perhaps we will be able to drop the "old" way of passing the ID, class="wp-image-1234".
Special handling of the width="123" attribute. In HTML 5.0 is has to be in pixels, but since the width of the editor is different than the width of the theme, the results would often be unexpected. This impacts mostly images that are resized when the user drags the corners or when image dimensions are set directly (see Enhancement: Inspector interface for setting pixel dimensions of image #4914). We will need better solution for these cases, perhaps recalculating the number when displaying the image on the front-end according to the theme's width.
To fix this for the front-end:
Add new default size 2x large, 2048px max width or height.
Add some logic when processing <img> tags and adding srcset, etc. that will produce usable sizes attribute. It will depend on the new data-* attribute and take into account theme's width when calculating sizes. If we are going to recalculate hard-coded width attributes (see above), this can be done here and the values used in both attributes. Alternatively we can set the width in percentage (HTML 4.0 style) in the editor, then replace them with pixels at this point.
Implementing all of the above will ensure all images are always "retina ready" both in the editor and on the site. It will also improve handling on the front-end and optimize image loading there.
This will also affect other enhancements, mostly #4914. Also, as described in #6131 the themes will be able to add more precise sizes attributes for the different images.
This is a "mini-proposal" on how to handle images in the editor and the front-end (follow-up from #4914).
Currently:
srcsetattribute, but thesizesattribute is pretty useless as it only refers to the full size image file:sizes="(max-width: 6000px) 100vw, 6000px".To fix this in the editor:
srcsetattribute that will also list 2x large size (so images are retina ready). This is a new size and will have to be added to the default WP sizes, see below.srcsetandsizes attributes a bit differently. Ideally that should have the attachment ID, something likedata-wp-attachment-id="1234". Then perhaps we will be able to drop the "old" way of passing the ID,class="wp-image-1234".To fix this for the front-end:
<img>tags and addingsrcset, etc. that will produce usablesizesattribute. It will depend on the new data-* attribute and take into account theme's width when calculating sizes. If we are going to recalculate hard-coded width attributes (see above), this can be done here and the values used in both attributes. Alternatively we can set the width in percentage (HTML 4.0 style) in the editor, then replace them with pixels at this point.Implementing all of the above will ensure all images are always "retina ready" both in the editor and on the site. It will also improve handling on the front-end and optimize image loading there.
This will also affect other enhancements, mostly #4914. Also, as described in #6131 the themes will be able to add more precise
sizesattributes for the different images.