title: Hiding images that failed to load
body: <p>I have an Android application that generates some HTML which is rendered locally, in a Webkit view.</p>
  
  <p>The details of the HTML generation aren't really that important except for: </p>
  
  <ul>
  <li>the bulk of it comes from one place, and I cannot change it</li>
  <li>the template around that HTML (including headers, footers, HEAD etc), the CSS, and Javascript is under my control.</li>
  <li>most images are under my control, and rendered separately from the untouchable HTML. These images come from local disk, and do not require the network. It can be assumed that these images are always available.</li>
  <li>the untouchable HTML contains images which would, ideally be displayed. If the network is unavailable, it is these images that would fail to load.</li>
  <li>the complete HTML file is likely to be stashed to disk, long before it is rendered. i.e. we cannot render different HTML based on network availability.</li>
  </ul>
  
  <p>The app is likely to be offline for at least some of the time, so I wish to handle the case where images fail to load. </p>
  
  <p>The images in question are predominantly 1x1 tracking images, but may include images that should be visible if they're available.</p>
  
  <p>Without invoking JQuery, or an external library, what would you advise my plan of attack?</p>
  
  <p>I have thoughts on how to do this, but realise that they are many pitfalls to worry about:</p>
  
  <ul>
  <li>with a CSS selector, select all the images that haven't loaded (is there such a selector?) and use <code>display:none;</code>.</li>
  <li>with Javascript, set the <code>alt</code> attribute on every image to the empty string. This would need to be done on <code>document.onLoad</code>?</li>
  <li>check the availability of the network, and then using CSS hide all images with @href~=^http. I'm not sure how/when to apply this style.</li>
  </ul>
  
  <p>If it helps, for this problem, I seem to have the following sub-problems. It is not clear the optimal strategy for any of them:</p>
  
  <ul>
  <li>how to determine the loaded-ness of the images or the state of the network.</li>
  <li>how to hide/mask the failed to load images, such that it is not detectable by the user that the image is missing.</li>
  <li>when to perform these tasks (e.g. when the document/window has finished loading?)</li>
  <li>how to apply them.</li>
  </ul>
  
  <p>Any thoughts, code, suggestions would be gratefully received.</p>