Hi Kouhei,Could you help me with a platform/loading design question for https://crbug.com/335630145?Lazy loaded image resources are created early in ResourceFetcher::RequestResource, but may not actually load (also via ResourceFetcher::RequestResource) until much later. We support the sec-ch-width header which is set to the layout width of the image. At the time we actually send the first lazy load image request in ResourceFetcher::RequestResource, we can have two sec-ch-width values:1. resource->GetResourceRequest() has a sec-ch-width header set based on the initial layout width.2. params.MutableResourceRequest() has a sec-ch-width header set to the current layout width.We have a bug because #1 is used for the request and sends the out-dated layout width. This hacky patch fixes the bug, but seems out of place. Do you know if there is a better approach to fix this bug?
(re-sending from pdr@chromium.org)Here's the stack for setting the Sec-CH-Width header:
BaseFetchContext::AddClientHintsIfNecessary
FrameFetchContext::AddClientHintsIfNecessary
FrameFetchContext::PopulateResourceRequest
PrepareResourceRequest
ResourceFetcher::PrepareRequest
ResourceFetcher::RequestResource
ImageResource::Fetch
ImageResourceContent::Fetch
ImageLoader::DoUpdateFromElement
In the auto sizes lazy loaded image case, an initial request will be created and stored in the memory cache, but won't be sent to the network. If we later need to request the lazy loaded image, we will make another call to ImageLoader::DoUpdateFromElement, which will create another request with the updated sec-ch-width header, but we will then send the original cached request to the network.
Do we need to store deferred resources in the memory cache? I wonder if an approach like this patch would be a good path forward (note: currently fails some tests)?
On Mon, May 13, 2024 at 12:06 AM Kouhei Ueno <kou...@google.com> wrote:+loading-dev, hiroshigeHi Philip,Thanks for reaching out!How about we defer computing Sec-CH-Width header value until the very end instead?I'm happy to look into this in more detail but would you point me to where the header value is originally computed+set? I couldn't find it from a quick code search.On Mon, May 13, 2024 at 8:27 AM Philip Rogers <p...@google.com> wrote:Hi Kouhei,Could you help me with a platform/loading design question for https://crbug.com/335630145?Lazy loaded image resources are created early in ResourceFetcher::RequestResource, but may not actually load (also via ResourceFetcher::RequestResource) until much later. We support the sec-ch-width header which is set to the layout width of the image. At the time we actually send the first lazy load image request in ResourceFetcher::RequestResource, we can have two sec-ch-width values:1. resource->GetResourceRequest() has a sec-ch-width header set based on the initial layout width.2. params.MutableResourceRequest() has a sec-ch-width header set to the current layout width.We have a bug because #1 is used for the request and sends the out-dated layout width. This hacky patch fixes the bug, but seems out of place. Do you know if there is a better approach to fix this bug?--kouhei