Search code examples
javascripthtml5-canvaswebgl

Do I need to wait until DOMContentLoaded before I can create a canvas element and render using WebGL or Canvas 2D?


I want to render some items using WebGL and Canvas 2D on a page, mainly part of some basic fingerprinting.

Do I need to wait until DOMContentLoaded before doing this, or can I do it before DOMContentLoaded?

The reason I ask is DOMContentLoaded may not be ready for a while if the page is large/badly created, so I'd rather not wait until then if it's not necessary.

Thank you for your time.


Solution

  • Yes you can create a canvas, a context and use it to render something before the DOM is finished loading.