A "new" tag for the web:
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).
Table of Contents
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
- HTML import does not look like happening
- No more static generators for something as simple as an
- 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):
<!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.
- At this point
includecannot guard against infinite recursion
Do the usual GitHub fork and pull request dance. Add yourself to the contributors section of [package.json] too if you want to.
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.