I noticed that when I do something like this (with jQuery, but I don’t think it matters):
$("#myDiv").html("<img src='/image.png'/> this is my image.");
The browser displays the text first, and then the image is loaded, and shifts the text to the right which creates a horrible flickering effect.
The image doesn’t appear to be cached by the browser. Any idea why ? How can I avoid this phenomena when loading images into the DOM ?
How can I avoid this phenomena when loading images into the DOM ?there are two major methods (may be more :))1) Set the actual size of the img
<img with='20' height='20' src='...' />or via CSS style.2) Use image preload and insert your code only when image is loaded
ps: there is a serious bag in SO engine – code formatting does not want to combine with numbered listing. So I removed the list.