<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>248025</bug_id>
          
          <creation_ts>2022-11-16 23:21:58 -0800</creation_ts>
          <short_desc>Dynamically added loading=&quot;lazy&quot; image when already is not reusing the cached image when available</short_desc>
          <delta_ts>2022-11-23 16:42:57 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Images</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=216979</see_also>
          <bug_file_loc>https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-available.html</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar, WPTImpact</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Karl Dubost">karlcow</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1913100</commentid>
    <comment_count>0</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-11-16 23:21:58 -0800</bug_when>
    <thetext>Steps to reproduce 
1. Go to http://wpt.live/html/semantics/embedded-content/the-img-element/image-loading-lazy-available.html
2. Scroll to the bottom

Expected:
PASS

Actual: 
FAIL


https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-available.html


The image which is added to the DOM is in the cache already, but it is not added until scrolling. 
And when the image is being finally reached, it downloads it again with a 200, instead of reusing the cached image.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913101</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-11-16 23:22:09 -0800</bug_when>
    <thetext>&lt;rdar://problem/102453623&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913104</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-11-16 23:31:58 -0800</bug_when>
    <thetext>There is also 
https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-use-list-of-available-images.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913789</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-11-20 18:12:24 -0800</bug_when>
    <thetext>ha interesting in 
https://html.spec.whatwg.org/multipage/images.html#the-list-of-available-images


&gt; 4.8.4.3.3 The list of available images
&gt; 
&gt; Each Document object must have a list of available images. Each image in this list is identified by a tuple consisting of an absolute URL, a CORS settings attribute mode, and, if the mode is not No CORS, an origin. 


There is a note:

&gt; The list of available images is intended to enable synchronous switching when changing the src attribute to a URL that has previously been loaded, and to avoid re-downloading images in the same document even when they don&apos;t allow caching per HTTP. It is not used to avoid re-downloading the same image while the previous image is still loading.


And in https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data

Step 6.3

&gt; If the list of available images contains an entry for key, then:
&gt; 
&gt; * Set the ignore higher-layer caching flag for that entry.
&gt; 



And this is a similar test case
http://wpt.live/html/semantics/embedded-content/the-img-element/image-loading-lazy-use-list-of-available-images.html
https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-use-list-of-available-images.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913790</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-11-20 18:28:45 -0800</bug_when>
    <thetext>I also opened https://github.com/whatwg/html/issues/8524
to be double sure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1914399</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-11-23 16:42:40 -0800</bug_when>
    <thetext>Confirmed 

1. The image should be reused. 
   https://github.com/whatwg/html/issues/8524
2. The two WPT tests are duplicates with the second one being probably better.
   https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-available.html
   https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/image-loading-lazy-use-list-of-available-images.html


According to the specification:
https://html.spec.whatwg.org/multipage/images.html#the-list-of-available-images


The browser should build a list of available images with the following parameters/requirements.

Each Document object must have a list of available images:
 
* Each image in this list is identified by a tuple consisting of an 
  * absolute URL, 
  * a CORS settings attribute mode, 
  * and, if the mode is not No CORS, an origin.
* Each image furthermore has an ignore higher-layer caching flag.


When switching to another Document:

* User agents may copy entries from one Document object&apos;s list of available images to another at any time (e.g. when the Document is created, user agents can add to it all the images that are loaded in other Documents), 
* but must not change the keys of entries copied in this way when doing so, 
* and must unset the ignore higher-layer caching flag for the copied entry.


* User agents may also remove images from such lists at any time (e.g. to save memory).
* User agents must remove entries in the list of available images as appropriate given higher-layer caching semantics for the resource (e.g. the HTTP `Cache-Control` response header) when the ignore higher-layer caching flag is unset.


AND as a Note

The list of available images is intended to enable synchronous switching when changing the src attribute to a URL that has previously been loaded, and to avoid re-downloading images in the same document even when they don&apos;t allow caching per HTTP. It is not used to avoid re-downloading the same image while the previous image is still loading.

AND Note

The user agent can also store the image data separately from the list of available images.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>