This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
RFC: Use Sharp for image optimization if installed #27055
Labels
created-by: Chrome Aurora
PRs by the Google Chrome team: https://web.dev/aurora
What I'm proposing:
Why I'm proposing this
Sharp is a lot faster than Squoosh for this use case. This fact has been noticed by the community since Next.js moved from Sharp to Squoosh, and is an ongoing source of complaints. Some users say this is preventing them from using the image component entirely.
We have no reason to believe that Squoosh will be competitive with Sharp for this use case in the near future.
The two reasons Next.js switched to Squoosh are both addressed by this solution:
How I propose to do this
I propose a solution that checks for the availability of Sharp at server startup using something like this:
We would also do a similar check during SSR or SSG, as part of the default loader provided with the image component. The default loader is what integrates with the image optimizer, so If that loader is called during production, and sharp is not installed, we can log a warning message on the server such as the following:
WARNING: For production image optimization with Next.js, the optional 'sharp' package is strongly recommended. Run 'yarn add sharp' or install sharp globally, and Next.js will use it automatically for image optimization.
The Squoosh code will continue to exist in the Next.js codebase, as it is adequate for a development server use case (though even in that context, Sharp will be used if it available).
The Sharp integration code (similar to what was removed in this PR) will be added back into the codebase, to make use of the Sharp library if it is available.
The text was updated successfully, but these errors were encountered: