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
Our site http://hacktj.org/ loads lots of images, decreasing site performance. One solution would be lazy loading images using the attribute on the img element, but an even nicer solution would be to use the HTML picture element along with (optional) lazy loading.
Describe the solution you'd like
at build-time, use Webpack to convert JPGs and PNGs to a variety of formats (perhaps make this opt-in somehow, to avoid long build times?)
replace the single img with a picture (with optimized images and original as a fallback)
replacing HTML elements might not be possible with the current react-scripts
maybe InterpolateHtmlPlugin and other related plugins could be adapted to do this
or maybe users could use this for images:
import{OptimizedPicture}from"react-scripts";constMyComponent=()=>(<><OptimizedPicturesrc="unoptimized.png"alt="A good alt."/><OptimizedPicturesrc="unoptimized-and-lazy.png"alt="Another good alt."loading="lazy"/></>);/* // instead of:const MyComponent = () => ( <> <img src="unoptimized.png" alt="A good alt." /> <img src="unoptimized-and-lazy.png" alt="Another good alt." loading="lazy" /> </>);*/
CRA should convert to the following filetypes:
JPEG 2000
JPEG XR
WebP
If loading="lazy" is passed to the image and width and height are not provided, CRA should automagically compute the dimensions of the image and pass those as width and height to avoid layout shift.
Describe alternatives you've considered
The current method to do this: Users could create a prebuild script to convert/optimizes images, and then manually write picture instead of img (and they could even create their own OptimizedPicture component). However, this results in a lot of repeat code across projects, which is why I think this should be in react-scripts.
Additional context
n/a
The text was updated successfully, but these errors were encountered:
thanks for the reply! that article actually inspired this feature request; my opinion is that CRA should automatically optimize images and/or use <picture>. Leaving img optimization up to CRA users makes for a ton of repeat code across projects, and is a little inconvenient because it doesn't integrate cleanly with CRA's build system (i.e., instead of using Webpack you have to use your own prebuild script to convert images)
Is your proposal related to a problem?
Our site http://hacktj.org/ loads lots of images, decreasing site performance. One solution would be lazy loading images using the attribute on the
img
element, but an even nicer solution would be to use the HTMLpicture
element along with (optional) lazy loading.Describe the solution you'd like
img
with apicture
(with optimized images and original as a fallback)InterpolateHtmlPlugin
and other related plugins could be adapted to do thisCRA should convert to the following filetypes:
If
loading="lazy"
is passed to the image andwidth
andheight
are not provided, CRA should automagically compute the dimensions of the image and pass those aswidth
andheight
to avoid layout shift.Describe alternatives you've considered
The current method to do this: Users could create a prebuild script to convert/optimizes images, and then manually write
picture
instead ofimg
(and they could even create their ownOptimizedPicture
component). However, this results in a lot of repeat code across projects, which is why I think this should be in react-scripts.Additional context
n/a
The text was updated successfully, but these errors were encountered: