I have pre-rendered HTML fragments in my filesystem. Is it possible to load HTML fragments in backbone.js? I'm looking for something similar to ng-include of Angular.js
for example, in my file system (frag.html)
<h1>I'm a fragment</h1>
Should be injected to the template in a given placeholder location
<div id="ph">
<!-- INJECTED -->
<h1>I'm a fragment</h1>
</div>
Suppose, we have this placeholder:
and this HTML in frag.html file:
Let us define our custom
PrerenderedView
with a specialrender
method with the jQuery functionload
inside:At the moment of instantiation of the
PrerenderedView
we should pass an optionajax_template_path
(which is 'frag.html' in our case).And, of course, we do not forget about Same Origin Policy if we are going to work without a server. For example, we can start chrome with the flag '--allow-file-access-from-files'.