Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active Aug 29, 2015
Embed
What would you like to do?
Loads an external HTML template inside a script tag.
(function($) {
// <script type="text/x-html-template" data-src="url" async></script>
$("script[type='text/x-html-template']").each(function() {
var $el = $(this);
var src = $el.data('src');
if (!src) return;
$.ajax({
url: src,
dataType: 'text',
async: $el.prop('async') || false,
cache: false,
success: function(data) {
$el.text(data);
}
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment