Pregunta

With the new KnockoutJS native DOM-enabled templating life's gonna be easy.

But sometimes pages contains millions of them, and all templates are static or just i18n'zed. So it would be great to retrieve templates from server via separate HTTP calls, so the browser will be able to cache them as static files.

It will give a great reduce in traffic and whole server load! Pages will be light and contain only changed data. Templates stored in CDN. It's a dream!

It was possible with jQuery.tmpl and require.js. But how to do it with knockout itself?

It would be perfect to load templates by name on demand, like an php __autoload() for templates, but at least it would be great to somehow include templates as remote html files to the page, and parse them for knockout.

Do you know how to do it?

¿Fue útil?

Solución

There are several ways to accomplish loading templates from external files.

In my opinion, the best option is to use the Knockout External Template Engine available here.

If you want some more basic ideas, I had a post from last year that describes some thoughts on the topic here.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top