knockout-amd-helpers
knockout-amd-helpers copied to clipboard
Module Binding: require() for the template source should not have to wait until the module is downloaded
With the current implementation, ko.templateSources.requireTemplate.prototype.text() will be executed only after templateBinding.data observable is mutated with a non-null value, i.e. when the module is downloaded and instantiated. That is when the 'if' condition on the underlying template binding will be satisfied.
The performance of the Module binding should improve significantly if the template source is downloaded in parallel with the module source. The init() function of the "module" binding can check whether the module name points to an external template, and execute a require() call without a callback. This will initiate the download of the template source before Knockout template is executed. amdTemplateEngine will execute require() for the template source exactly as it does today. Require.js will be smart enough to realize that download of the template source has already started (or perhaps is already done), and invoke the callback much sooner than it would have done if the download had to be initiated then.