Skip to content

A web component for doing HTML includes: <html-include src="..."></html-include>

License

Notifications You must be signed in to change notification settings

reiver/html-include

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

<html-include>

<html-include> is a web component that lets you include HTML at one URI into another HTML page.

You can think of this as a web-browser-side edge-side-include (ESI) — if you are familar with the server side <esi:include>.

Example

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Example</title>

		<script src="components/html-include.js"></script>
	</head>

	<body>
		<html-include title="footer" src="partials/header.html"></html-include>

		<p>
			Hello world!
		</p>

		<html-include title="footer" src="partials/footer.html"></html-include>
	</body>
</html>

Basic Usage

The most basic way of using <html-include> is:

<html-include src="footer.html"></html-include>
<html-include src="includes/header.html"></html-include>
<html-include src="path/to/the/file.html"></html-include>

Note that in this basic usage we just set the src attribute to point to the URI we want to include.

Advanced Usage

A more advanced way using <html-include> is:

<html-include title="footer" src="footer.html" />

Note the addition of the ‘title’ attribute.

This usage will show a more informative loading message. I.e., instead of showing:

Loading…

… it will show:

Loading “footer”…

I.e., it includes whatever is in the ‘title’ attribute in the loading-message.

Debugging

If you need to debug what <html-include> is doing you can use the debug="true" attribute. For example:

<html-include debug="true" src="footer.html" />
<html-include debug="true" title="footer" src="footer.html" />

Note the addition of the ‘debug’ attribute, with the value set to the string "true".

This will call console.log() with logs that try to provide inside into what is doing internally.

About

A web component for doing HTML includes: <html-include src="..."></html-include>

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published