From the course: Learning Web Components

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use HTML imports

Use HTML imports

From the course: Learning Web Components

Start my 1-month free trial

Use HTML imports

- [Instructor] Let's modify our original template example from the first chapter to use HTML Imports to store the template content in a separate file that we can use in more than one page. Let's open the file import1_start.html, and let's also open the file template.html. The template file contains the template code, well, most of it, anyway, from the previous chapter. I've placed it into its own file for this example. So back in the main page, we need to start by writing the import statement to import the template. And you can see that I've already included the polyfill right here about any imports that I want to use. Now, for polyfilling reasons, this has to proceed any imports you want to use. And in browsers such as Chrome that natively support HTML Imports, this actually won't be used at all. So let's go ahead and add our link. So I'll type link rel="import," and we get a reference to our template, which is right here, and we'll give this an ID, and we'll call it tmplFile. Now…

Contents