To expand the kinsho (correct) answer:
For security and maintenance reasons, you should carefully embed raw HTML directly into documents. This can disrupt event listeners, break the DOM parser, and potentially expose security vulnerabilities.
Usually, the best way to load lazily is to send encoded data (such as JSON or XML) to the client and process the result accordingly. For basic HTML, you can use a template solution. Even iframe can be better than inserting <div><h1>Hello</h1><table><tbody><td><tr>1</td></tr><tr><td>2</td></tr></tbody></table></div> * into the innerHTML element.
Also, before you start lazy loading for your site, consider whether it's really worth it. An additional HTTP request is noticeably more expensive than just downloading the data right away, and any HTML code entered through Javascript will not be visible to web search crawlers. So if you enter only a small amount of static information, this is really not worth the trouble.
* Can you find the parsing error? Now imagine that you are doing this for a standard size HTML document.
Jeffrey sweeney
source share