Skip to content

miragecraft/x-include

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 

Repository files navigation

X-Include

Cross-site HTML include via <script> tags in the manner of JSONP.

Full documentation

Basic features:

  • Bypass CORS, usable with file:// protocol
  • Retains the synchronous programming model
  • Preserves order-of-evaluation for nested includes
  • Parser-blocking for FOUC suppression

Advanced features:

  • data-dir attribute allows specifying include base directory
  • link() function to remap relative paths inside includes
  • data and template variables for passing data to include files
  • <include-once> tag allowing smarter resource management
  • Detect and block infinite include loops (bypass-able)

The following just works, even from your local drive:

<!DOCTYPE html>
<html>
<head>
  <script src="js/x-include.js" data-dir="../includes"></script>
  <script>include('head.js', {title: "Hello World"})</script>
</head>
<body>
  <script>include('header.js')</script>
  <main>
    <h1>Lorem Ipsum</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pellentesque neque vitae varius facilisis.</p>
  </main>
  <script>include('footer.js')</script>
</body>
</html>
// head.js
include.html(x=>`
  <title>${x.data.title}</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/svg+xml" href="${x.link("../img/favicon.svg")}">
  <link rel="stylesheet" media="screen" href="${x.link("../css/style.css")}">
`)

About

Cross site HTML include via <script> tag in the manner of JSONP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published