image.onload event and browser cache
As you’re generating the image dynamically, set the onload property before the src. Fiddle – tested on latest Firefox and Chrome releases. You can also use the answer in this post, which I adapted for a single dynamically generated image: Fiddle