Include: Fast, drop and forget include HTML for the web
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
lib
test
.gitignore
HISTORY.md
LICENSE
README.md
demo.png
filled_filter.svg
index.html
package.json

README.md

Include JS

A "new" tag for the web:

<include src="/path/to/import/file.html"/>

The main reason why static generators (they are quite popular) need to exist in this day and age is the lack of an HTML import facility. With current HTML you can include pretty much everything, except for HTML itself (pretty lame IMHO).

demo

Table of Contents

Goals

The goals of this library are a completely seamless experience including content via the <include> tag. The experience needs to be seamless in terms of:

  • Simplicity: should work like a native tag
  • Backward Compatibility: fails nicely in older browsers
  • Speed: no screen flickering, fast load times (achieved via localStorage and pseudo-pipelining)

Why Include

  • HTML import does not look like happening
  • The import syntax is not declarative, it still needs Javascript to insert things into the page
  • No more static generators for something as simple as an include
  • Avoid all the performance penalties and flicker associated with dynamic includes (via smart caching)

Hello World Example

Mandatory Hello World example (link takes you to JSFiddle):

file header.html:

<h1>ACME Inc</h1>

file footer.html:

<footer>Copyright 2016</footer>

file index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <script src="../lib/include.js"></script>
  </head>
  <body>
    <include src="header.html"></include>
    <article>
      <p>We are ACME Inc. We manufacture <b>everything</b>.</p>
    </article>
    <include src="footer.html"></include>
  </body>
</html>

The fiddle is modified to load the files directly from GitHub, since there is no way to store files as fiddles.

Known Limitations

  • At this point include cannot guard against infinite recursion

Testing Include

There are three visual tests in the demo.html file. Additionally you can see the results for 15 browser shots in the shots.html file.

Contributing

Do the usual GitHub fork and pull request dance. Add yourself to the contributors section of [package.json] too if you want to.

License

Released under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.