Live data from Hacker News

Fragment.js - A tiny tool for loading html fragments and templates

danielrapp.github.com

11–14 of 14 posts

Re: Fragment.js - A tiny tool for loading html fragments and templates

#11
post #9
post #6

It's a nice fun little tool -- but it's rather inefficient in terms of the number of AJAX requests that it needs to do in order to fetch the templates. The rather simple linked page needs a total of 3 AJAX requests, one for each template. As your app (especially mobile apps) needs more templates, it probably won't be very performant. There's a reason why Ember and other frameworks prefer their templates to be embedde…

Default behavior for ngView in Angular is to fetch the template with Ajax. You have your view html files in a partials directory.

I believe Angular will search for inline templates first, so as long as you use the same path for the template name it won't attempt any AJAX fetching.

Re: Fragment.js - A tiny tool for loading html fragments and templates

#12
post #8
post #7

If you added a build process that actually pulled in the source files for a bundled production file you might have something similar to RequireJS for templates. Cool stuff.

Doesn't require.js include plugins that will pull in compiled templates for you for the major templating libraries already? (underscore, mustache etc)?

Yes it does. This one precompiles handlebars for you: https://github.com/SlexAxton/require-handlebars-plugin

Re: Fragment.js - A tiny tool for loading html fragments and templates

#13
post #12
post #8

Earlier quoted context omitted.

Doesn't require.js include plugins that will pull in compiled templates for you for the major templating libraries already? (underscore, mustache etc)?

Yes it does. This one precompiles handlebars for you: https://github.com/SlexAxton/require-handlebars-plugin

That's pretty sweet. So if you run the r.js optimizer, you'll be serving minified, precompiled templates to the client.

Re: Fragment.js - A tiny tool for loading html fragments and templates

#14
post #13
post #12

Earlier quoted context omitted.

Yes it does. This one precompiles handlebars for you: https://github.com/SlexAxton/require-handlebars-plugin

That's pretty sweet. So if you run the r.js optimizer, you'll be serving minified, precompiled templates to the client.

Indeed. We use it all the time!
Post reply on HN