Skip to content

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

Closed
@ascorbic

Description

@ascorbic

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! 

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featurecode contributing to the implementation of a feature and/or user facing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions