JSFiddle - React, Tailwind, and code Playground

HTML

Foo

JavaScript

var tpls = {};
var tpl_dir = '/path/to/templates';

function require_template(templateName, callback) {
    var template = tpls[ templateName ];
    if ( !template ) {
        var tmpl_url = tpl_dir + '/' + templateName + '.html';
        
        $.ajax( tmpl_url, {
            method: 'GET',
            contentType: 'text',
            success: function (data) {
                tpls[ templateName ] = _.template( data );
                if( typeof callback === "function" ){
                    callback();
                }
            }
        });
    }
}