How to import HTML template file into JavaScript module

Marian Čaikovski
5 min readApr 28, 2021

import template from './temlplate.html'; does not work in a browser.

It is much easier to develop web applications when HTML templates and JavaScript stay separate. The template of the illustration is borrowed from Human Vectors by Vecteezy.

Although some frameworks oblige developers to mix everything, generally web development is easier when the layout, styles and application logic are separated. You layout a page and its component in .html files, style them in .css files and add the logic implemented in many tiny modules each dedicated…

--

--

Marian Čaikovski

Java, JavaScript and SQL developer. Interested in data collection and visualization.