Modern vanilla JavaScript to split a long HTML file

I am creating an HTML-CSS-JavaScript-PHP contact form and I have an HTML file which has become very long for me to work with.

Also, some of the lines are by themselves very long due to nesting and requires significant horizontal scrolling to be edited and the overall file is just hard for me to read and edit.


I want to have one main HTML file which contains inclusions of other HTML files (modular HTML).

HTML file inclusion was supported in the past (in HTML itself), but no more for some reason, yet I know that it can be done with JavaScript.


What would be a very modern (ES 10,11,12?) vanilla JavaScript way to split a long HTML file into several?

JavaScript is a poor way to include HTML files as there are many ways that JavaScript can and does break. https://kryogenix.org/code/browser/everyonehasjs.html

As you’re using PHP, I highly recommend using that to bring together different HTML pages instead.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.