Problem/Motivation
The image URLs can be different based on the Accept header sent by the browser, but since the cache context for the Accept header is not being added, whatever is rendered first will be cached for all browsers. This leads to browsers not supporting WebP showing WebP images, or browsers supporting WebP not showing the WebP version.
Proposed resolution
Add the headers:accept cache context.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3212705-14.patch | 2.96 KB | duwid |
| #13 | 3212705-13.patch | 2.96 KB | seanb |
Comments
Comment #3
seanbComment #5
kubrick commentedI'm still having this issue on 1.1.
Whichever version (jpg/webp) gets hit first gets cached and served to every user.
Comment #6
kubrick commentedStill can't get this to work. If a webp capable browser hits the page first it caches the page with webp url's for all visitors. (and vice versa)
Not that much of an issue these days as there's not a lot of users using on browsers that don't support webp.
Comment #7
kubrick commentedI've looked into this again, and it seems if you have page caching enabled Drupal will always serve the same page to all anonymous users, regardless of headers.
https://www.drupal.org/docs/8/api/cache-api/cache-contexts#internal
Maybe it would be an option to always render WebP by default (if module available) and have a JavaScript based fallback load the JPG version on older browsers.
Comment #8
seanbSince most browsers support WebP, I would prefer not to have a lot of code to deal with this issue. However, since Internal Page Cache could have significant benefits for smaller sites, I think it would make sense to have something to deal with this.
We could add a checkbox to the settings page when a WebP module AND Internal Page Cache are enabled. When the checkbox is enabled, we skip the HTTP_ACCEPT header check and always serve WebP. Would this help your use case?
Comment #9
kubrick commentedSure, that would work. :)
Comment #10
seanbI'm slowly thinking that we should remove the check for the HTTP_ACCEPT header now most browsers support WebP. Any thoughts?
Comment #11
kubrick commentedYes, I agree. I see no harm in just serving WebP to all users if one of the WebP modules is enabled.
Comment #12
seanbCould you create a PR for this?
Comment #13
seanbCreated a patch that should fix this.
Comment #14
duwid commentedThank you for the patch. I rerolled it to work with version 1.3.1
Comment #16
seanbThanks, went ahead and committed this. All major browsers support WebP by now. No need to serve WebP conditionally anymore.