Skip to content

Instantly share code, notes, and snippets.

@royling
Last active October 26, 2015 15:06
Show Gist options
  • Save royling/91288f360f86aada1f70 to your computer and use it in GitHub Desktop.
Save royling/91288f360f86aada1f70 to your computer and use it in GitHub Desktop.
Use <link> to define templates and load them ondomready
$(function() {
var tplts = Object.create(null), importLinks = $('link[rel="import"]');
// load all imported templates
importLinks.each(function(idx, elem) {
$.get(elem.href, function(data) {
var view = elem.getAttribute('href');
tplts[view] = data;
if (Object.keys(tplts).length == importLinks.length) {
// all are loaded
console.info("all templates are loaded:", tplts);
}
}, 'text');
});
});
@royling
Copy link
Author

royling commented Jun 25, 2014

Define a template like this:

<link rel="import" href="partials/template1.html">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment