Ask coding questions

← Back to all posts
Is image or canvas faster
Coder2195Text (35)

Which is faster to render 121 tiles?
121 img elements or 121 images drawn on canvas
I want to opmitze the faster one

Answered by 19wintersp (1121) [earned 5 cycles]
View Answer
19wintersp (1121)

I think it's faster to have a canvas, because there are less elements. Note however that canvas would require using JavaScript, and an image is purpose-built to draw images. Are you showing multiple, different ones, animating them, or just showing them statically?

Coder2195Text (35)

@19wintersp I don't need think I need sure and maybe some proof

realTronsi (912)

@Coder2195Text they aren't comparable. You can just test it yourself though and check runtime

19wintersp (1121)

@Coder2195Text They're for different things. If you're just loading images statically, use <img>s. As a rule of thumb, don't get JavaScript involved unless you need to.

Coder2195Text (35)

@19wintersp It's for a game a tile based game

19wintersp (1121)

@Coder2195Text If they're going to be constantly updated, use canvas.

Coder2195Text (35)

@19wintersp Yes there are 121 img there are multiple