Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Under what conditions does the Parse HTML event get called?

I am trying to debug a bottleneck in my rendering of an HTML page with multiple backbone views. I used Chrome Dev Tools's Timeline profiler and saw a big amount of Parse HTML events. My question is:

Does this necessarily mean the DOM was touched each time, or is the Parse HTML event also triggered when manipulating HTML in a detached jquery object?

like image 633
lior Avatar asked Oct 20 '22 04:10

lior


1 Answers

Disclaimer: I don't know anything about backbone except that it is a framework.

It can mean that the DOM was touched each time but it does not need necessarily. You will trigger parsing events obviously when you are loading HTML document and also when you are playing with one of these innerHTML, outerHTML, innerText insertAdjacentHTML, DOMParser interface but these are just tip of the iceberg. A lot of stuff will trigger parse HTML events.

For example:

setInterval(function(){
  var parser = new DOMParser();
  parser.parseFromString('<p>lorem</p>','text/html');
},5000);

This will trigger HTML parser every 5 seconds but it will not touch DOM. But when you use for example document.body.innerHTML = '<p>Hello</p>' you will trigger parsing events as well touch the DOM. So you can have parse events even if you are not directly touching the DOM.

like image 100
Blago Eres Avatar answered Oct 28 '22 15:10

Blago Eres