You can use the KnockOut custom binding for this.
Here's a really simple snap - keep in mind that this is just an idea:
ko.bindingHandlers.script = { update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var scriptName = ko.utils.unwrapObservable(valueAccessor()); $(element).html("<script src='" + scriptName + "'></script>"); } };
In your view (.html file):
<div data-bind="script:'dobinding.js'"></div>
I tested this, and I found that the script is actually being entered, parsed and executed, but it does not remain loaded in the DOM. This may or may not be a problem for you.
It seems that tagging may be the subject of Durendal. I still do not understand the reason, but I will update if I have the opportunity to look into it.
source share