<?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>6656</bug_id>
          
          <creation_ts>2006-01-18 15:12:26 -0800</creation_ts>
          <short_desc>Image loading continues when IMG elements or Image JavaScript objects are removed</short_desc>
          <delta_ts>2026-01-12 09:02:51 -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>Page Loading</component>
          <version>420+</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=35377</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Thomas Fuchs">thomas</reporter>
          <assigned_to name="Said Abou-Hallawa">sabouhallawa</assigned_to>
          <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>bryan</cc>
    
    <cc>chas.conway</cc>
    
    <cc>dpaddock</cc>
    
    <cc>graouts</cc>
    
    <cc>holidaymaker268</cc>
    
    <cc>ian</cc>
    
    <cc>javan</cc>
    
    <cc>jonlee</cc>
    
    <cc>julio.viera</cc>
    
    <cc>kyl3h0tchk1ss</cc>
    
    <cc>lbzwischenbrugger</cc>
    
    <cc>mrowe</cc>
    
    <cc>paradox460</cc>
    
    <cc>raushnigupta8</cc>
    
    <cc>rawatdeepakg</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>tonikitoo</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>webkitbugzilla</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>28847</commentid>
    <comment_count>0</comment_count>
    <who name="Thomas Fuchs">thomas</who>
    <bug_when>2006-01-18 15:12:26 -0800</bug_when>
    <thetext>When IMG elements or JavaScript Image objects are completely removed (setting .innerHTML of a container 
to an empty string or deleting the Image object) image loading continues in the background.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28848</commentid>
    <comment_count>1</comment_count>
      <attachid>5764</attachid>
    <who name="Thomas Fuchs">thomas</who>
    <bug_when>2006-01-18 15:13:26 -0800</bug_when>
    <thetext>Created attachment 5764
Simplified test cases for plain HTML, JavaScript Image objects and generated HTML (watch the activity window)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28849</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2006-01-18 15:18:19 -0800</bug_when>
    <thetext>It seems logical to me that removing the image completely from the page by the three means shown 
should cancel loading the image.  Thanks for the great test case Thomas.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>304</commentid>
    <comment_count>3</comment_count>
    <who name="Chas Conway">chas.conway</who>
    <bug_when>2007-09-19 08:29:22 -0700</bug_when>
    <thetext>I was about to file a similar bug regarding identical behavior with MJPG streams.  I am trying to switch an image&apos;s source between a static and motion jpeg file to save bandwidth when the video is not needed, but no matter what I do to it, short of reloading the page, it continues to load the MJPG data stream once it&apos;s been requested once.

http://discord.itg.uiuc.edu/testing/MJPG_test.html

This video stream may sometimes be black, but you will still see ~100KB/s in the activity monitor.  This test case shows that the MJPG stream continues downloading after switching the src to a static image and even after deleting the image&apos;s DOM node.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>289</commentid>
    <comment_count>4</comment_count>
    <who name="Dave Hyatt">hyatt</who>
    <bug_when>2007-09-19 13:31:46 -0700</bug_when>
    <thetext>This is actually by design.  I can see how it would be bad if the resource is large though.  (The idea is to go ahead and let the load complete so that the image gets into the cache to be resuable.)
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>285</commentid>
    <comment_count>5</comment_count>
    <who name="Chas Conway">chas.conway</who>
    <bug_when>2007-09-19 13:42:00 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; This is actually by design.  I can see how it would be bad if the resource is
&gt; large though.  (The idea is to go ahead and let the load complete so that the
&gt; image gets into the cache to be resuable.)
&gt; 

That&apos;s good to know.

I don&apos;t know much about MJPG resources;  can they be finite-length as well?  In this case the MJPG stream is live and continues on forever negating any reason to try caching it.  Is there a way to detect that the stream is not finite and cancel the behavior?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101804</commentid>
    <comment_count>6</comment_count>
    <who name="Wichert Akkerman">wichert</who>
    <bug_when>2008-12-08 02:08:26 -0800</bug_when>
    <thetext>What was the design decision made here?

This issue breaks image lazy loading tricks, making pages with many images below the fold extremely expensive for people using webkit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115337</commentid>
    <comment_count>7</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2009-03-26 09:03:54 -0700</bug_when>
    <thetext>&lt;rdar://problem/6726455&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117958</commentid>
    <comment_count>8</comment_count>
    <who name="Bryan Field-Elliot">bryan</who>
    <bug_when>2009-04-17 12:53:51 -0700</bug_when>
    <thetext>Can someone please advise what the status of this bug is? And what is the link in the previous comment for? (&quot;&lt;rdar://problem/6726455&gt;&quot;). Thank you.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>185571</commentid>
    <comment_count>9</comment_count>
    <who name="Kyle Hotchkiss">kyl3h0tchk1ss</who>
    <bug_when>2010-01-28 12:23:34 -0800</bug_when>
    <thetext>http://www.appelsiini.net/projects/lazyload .. Why can&apos;t the model of this plugin just be applied, or maybe when it sees something like this used, it doesn&apos;t ignore it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>193902</commentid>
    <comment_count>10</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-02-25 15:55:03 -0800</bug_when>
    <thetext>*** Bug 35377 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>194112</commentid>
    <comment_count>11</comment_count>
    <who name="">lbzwischenbrugger</who>
    <bug_when>2010-02-26 08:27:04 -0800</bug_when>
    <thetext>Finish loading or not


If the src attribute of an image is changed by javascript
a new Image will be loaded.
In some cases the previous loaded image is not fully loaded. It is a &quot;nice
idea&quot; to complete loading for caching reasons.
But there are some problems with that.


Loading continues also when an image Element is removed from
DOM tree or an Image object is deleted.


Dealing with partly loaded Images
-----------------------------------
I see 3 possibilities

A.) Continue loading even if the image is not requested anymore

WebKit Browsers continue loading. Firefox stops loading.
If the image is loaded to 99% it&apos;s cool to continue loading for cache.
If it&apos;s many times only 10% it makes the app slow.


B.) Stop loading, dump the partly loaded images

If the programmer needs to preload images he/she can do that with an Image Object.
It&apos;s also possible to create an Element with tagName &quot;img&quot; an, set the src Attribute and
set the style to display:none. If the images is needed change display property to &quot;&quot; or &quot;inline&quot; with javascript;


C.) Stop loading, save the partly loaded images. If the image is requested again load the rest of the image. 

see:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
14.16 Content-Range

That would be cool if it&apos;s really fast code.
I don&apos;t knoww if web servers loose speed with in aktive
&quot;Content-Range&quot; http header. This is als used for 
large file downloads.

More details on this header:
http://www.west-wind.com/WebLog/posts/244.aspx
	

WebKit Status:
--------------
There is no possibility for programmers to abort loading an image.
Webkit has a really fast image rendering and zoom engine. 

For web applications (browser maps) that deal with lots of images 
it&apos;s good to have excellent image rendering.
However, the user will not be really satisfied - because of this
image loading issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>197518</commentid>
    <comment_count>12</comment_count>
    <who name="">lbzwischenbrugger</who>
    <bug_when>2010-03-09 03:22:36 -0800</bug_when>
    <thetext>Here is a more komplex testcase:
http://www.khtml.org/webkitbug/
It&apos;s webmap. if you zoom in/out very fast, firefox is fast loading the images.
Btw. if an images has in Etag but is in cache, the image could be displayed immediately. If the ETag has changed the picture on the page can be changed for the new one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>217442</commentid>
    <comment_count>13</comment_count>
    <who name="paradox">paradox460</who>
    <bug_when>2010-04-26 19:20:52 -0700</bug_when>
    <thetext>This script is probably the most common use of this technique
http://www.appelsiini.net/projects/lazyload

An example can be seen here:
http://www.appelsiini.net/projects/lazyload/enabled.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>457820</commentid>
    <comment_count>14</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-08-26 15:42:33 -0700</bug_when>
    <thetext>It&apos;s my fault that this bug is about two separate issues now (removing an element or changing its src). Even though both are by design, these are not identical.

Perhaps bug 35377 should be un-duped.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>457857</commentid>
    <comment_count>15</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2011-08-26 16:53:20 -0700</bug_when>
    <thetext>I reopened bug 35377.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>457901</commentid>
    <comment_count>16</comment_count>
    <who name="">lbzwischenbrugger</who>
    <bug_when>2011-08-26 19:18:41 -0700</bug_when>
    <thetext>
I reported bug 35377 and also made a comment here for the same bug.
For me it looks pretty much the same.

There are many methods to cancel image loading:

img.setAttribute(&quot;src&quot;,&quot;&quot;);
img.src=&quot;&quot;;
img.parentNode.innerHTML=&quot;&quot;;
img.parentNode.textContent=&quot;&quot;;
img.parentNode.removeChild(img);
img.parentNode.replaceChild(img2);
(maybe not complete)


btw. when I reported this bug I was in Cambodia and had a slow internet connection. Bandwidth was about 300 kBit shared for a guesthouse, the ping indicated that it was a satellite link.
Under this conditions webkit browsers are not the first choice mainly because of the bug I think.
Now I&apos;m connected to the internet with a 10MBit line again and here I don&apos;t feel a bad impact of the bug. To find a good solution, the programmer maybe should simulate slow internet speed as you find in many parts of this world.
&quot;netem&quot; could do that for example.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430173</commentid>
    <comment_count>17</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2018-06-05 12:24:50 -0700</bug_when>
    <thetext>Talking to a dev from BaseCamp right now at WWDC.

&quot;In other browsers, doing something to get an IMG created does not synchronously start a network load - That only happens after the runloop spins.

WebKit synchronously starts the load, even JS immediately sets the src the null.

This is super duper wasteful in our app (We clone dom trees, etc etc)&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1430427</commentid>
    <comment_count>18</comment_count>
    <who name="Javan Makhmali">javan</who>
    <bug_when>2018-06-06 08:01:32 -0700</bug_when>
    <thetext>Hello, another Basecamp developer here with more details.

We use `MutationObserver` to detect when images are added to the DOM and swap their &quot;src&quot; attribute with a tiny placeholder image. Then we restore the original &quot;src&quot; as images are scrolled into the viewport. This technique is commonly referred to as “lazy loading” and is intended to avoid unnecessary network requests for images that may never be viewed.

Due to this WebKit issue, our approach doesn’t work in Safari because the original image is always loaded.

Additionally (this may be a separate issue), cloning &lt;img&gt; elements causes them to load *again* even if the cloned node is detached from the DOM. For example, running `document.body.cloneNode(true)` reloads all of its images. This affects our Turbolinks (https://github.com/turbolinks/turbolinks) library, which stores “snapshots” of pages by cloning them.

I made a video to help illustrate the problem: https://www.youtube.com/watch?v=p6bkcjoyP1M

In Safari (left), every image on the page is loaded initially, and then loaded again when scrolled into view. Cloning &lt;body&gt; loads all of its images once more.

In Chrome (right), only the first image loads initially and the rest are canceled. Cloning &lt;body&gt; makes no additional network requests.

My example application and its source code are available here: https://glitch.com/~jealous-moon

Thanks for your time!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>5764</attachid>
            <date>2006-01-18 15:13:26 -0800</date>
            <delta_ts>2006-01-18 15:14:44 -0800</delta_ts>
            <desc>Simplified test cases for plain HTML, JavaScript Image objects and generated HTML (watch the activity window)</desc>
            <filename>image_loading_bug.html</filename>
            <type>text/html</type>
            <size>554</size>
            <attacher name="Thomas Fuchs">thomas</attacher>
            
              <data encoding="base64">PGRpdiBpZD0iY29udGFpbmVyIj4KICA8aW1nIHNyYz0iZmFrZV9mcm9tX2h0bWwuanBnIiBhbHQ9
IiIgLz4KPC9kaXY+CjxzY3JpcHQ+CiAgLy8gY2FzZSAxIC0gaW4gSFRNTAogIGRvY3VtZW50Lmdl
dEVsZW1lbnRCeUlkKCdjb250YWluZXInKS5pbm5lckhUTUwgPSAiIjsKICAKICAvLyBjYXNlIDIg
LSBpbiBKUwogIHZhciBpID0gbmV3IEltYWdlKCk7CiAgaS5zcmMgPSAiZmFrZV9mcm9tX2pzLmpw
ZyI7CiAgZGVsZXRlIGk7CiAgCiAgLy8gY2FzZSAzIC0gZXhwYW5kZWQgSFRNTCBleGFtcGxlCiAg
dmFyIGh0bWxmcmFnbWVudCA9ICIiOwogIGZvcih2YXIgbG9vcD0wO2xvb3A8MTAwO2xvb3ArKykK
ICAgIGh0bWxmcmFnbWVudCArPSAoJzxpbWcgc3JjPSJmYWtlX2Zyb21faHRtbF9sb29wXycgKyBs
b29wICsgJy5qcGciIGFsdD0iIiAvPicpCgogIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjb250
YWluZXInKS5pbm5lckhUTUwgPSBodG1sZnJhZ21lbnQ7CiAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5
SWQoJ2NvbnRhaW5lcicpLmlubmVySFRNTCA9ICIiOwo8L3NjcmlwdD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>