Skip to content

viewport-based selection use case and caching #59

Closed

Description

@waldbaerkoch

Given the following example:

<img srcset="wolf-480.jpg 480w, ..., wolf-1920.jpg 1920w" sizes="...">

The same wolf-1920.jpg would be selected e.g. for

  • dpr=1, calculated display width=1920
  • dpr=1.5, calculated display width=1280
  • dpr=2, calculated display width=960
  • dpr=3, calculated display width=640
  • dpr=4, calculated display width=480

A cache could respond with the same cache entry for all these requests.

If the HTML is reduced to

<img src="wolf.jpg" sizes="100vw">

the same image would be selected or created for requests with client hint headers

  • DPR: 1, Width: 1920
  • DPR: 1.5, Width: 1280
  • DPR: 2, Width: 960
  • DPR: 3, Width: 640
  • DPR: 4, Width: 480

The server responds with

Vary: DPR, Width

But although it's the same image, a cache would have to create separate cache entries because the DPR and Width header values differ.
If the client sent a client hint with the needed instrinsic width (e.g. Instrinsic-Width: 1920) (the client has to calculate it in the srcset-w case anyway to compare it to the w descriptors), the server would respond with

Vary: Instrinsic-Width

A cache could respond to all the requests above with the same entry.

Activity

  1. waldbaerkoch commented on Sep 7, 2015

    @waldbaerkoch
    Author

    An alternative could be a way to use a Key header (http://mnot.github.io/I-D/http-key/draft-fielding-http-key-03.html) with the partition parameter based on the product of two header values, like

    Key: DPR*Width;partition=480:...:1920
    

    which is not (yet :-) defined.

  2. igrigorik commented on Sep 14, 2015

    @igrigorik
    Owner

    Hmm, that's a good suggestion - thanks. It does seem that reporting the intrinsic width would ease the implementation on the server: reduces fragmentation with Vary and does not require any acrobatics for Key. We'd still want to report DPR though.

    @yoavweiss any thoughts on this one?

  3. yoavweiss commented on Sep 15, 2015

    @yoavweiss
    Contributor

    I agree that in most cases, you'd want your server to respond to DPR+Width, which means redundant variance, and will be hard to cache.

    Replacing Width with a Width*DPR value would provide the server side the same information that it can receive today, while reducing the variance of the major use-case.

    I don't like Intrinsic-Width as that value's name, since in the browser we're using that to mean Width rather than Width*DPR (The incoming resource's intrinsic width is being corrected as a function of its srcset descriptor or the Content-DPR header).

    Maybe Physical-Width? (`Resource-Width' might have been a good fit as well, but our past use of it may cause confusion...)

  4. igrigorik commented on Sep 15, 2015

    @igrigorik
    Owner

    @yoavweiss as a slightly more radical version: what about changing current definition of Width? Granted, M46 is starting its rollout now, but I don't think it's too late... if we act fast? :)

    In terms of history: we specced CSS px values because we were using Width to describe both the resource and viewport width's. However, now that we've split those cases into separate headers, I think we can revisit that.

  5. yoavweiss commented on Sep 15, 2015

    @yoavweiss
    Contributor

    Yeah, we can try to get a semantics change in before M46 hits stable. Usage is still at 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions