Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use content negotiation to automatically return next-gen image formats #319

Closed
ascorbic opened this issue May 17, 2021 · 4 comments
Closed
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@ascorbic
Copy link
Contributor

Because next/image does not support <source> and <picture> tags, we cannot safely use next-gen image formats, as there is no way to provide a fallback. The best way to handle this is by automatically return an image format supported by the browser. This can be done by inspecting the Accept header sent in the request. ODB does not pass request headers, so the idea would be to use the same redirects that we use to redirect from the /_next URL to the ODB function, and embed the requested format in the URL.

This would be enabled by support for redirects by HTTP header

For example:

/_next/image*  url=:url w=:width q=:quality  /nextimg/:url/:width/:quality.avif  301! Header@Accept=image/avif
/_next/image*  url=:url w=:width q=:quality  /nextimg/:url/:width/:quality.webp  301! Header@Accept=image/webp
# Fallback for browsers that don't support next-gen images
/_next/image*  url=:url w=:width q=:quality  /nextimg/:url/:width/:quality  301! 
@lindsaylevine
Copy link

omg

@lindsaylevine lindsaylevine added next/image type: feature code contributing to the implementation of a feature and/or user facing functionality labels May 18, 2021
@EliteMasterEric
Copy link

EliteMasterEric commented May 23, 2021

+1 to this. I want my app to utilize WEBPs where supported without having to "live on the edge" and break the site completely for users who don't use a browser that supports WEBP.

This is a feature already present in the base NextJS server, as seen in its image optimizer. It checks the header of the incoming request, determines if the client supports a next-gen image format, and supplies it if so.

Without this feature, the changes mentioned in #133 are not useful to me.

@ascorbic
Copy link
Contributor Author

To be clear, this isn't something that we can currently support, but would be enabled when redirects by HTTP header are enabled

@ascorbic
Copy link
Contributor Author

This has been implemented using edge functions #1310

serhalp pushed a commit that referenced this issue Apr 5, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

3 participants