News for hackers. Stuff that matters.
Re:Backbone UI by Kilimanjaro on Tuesday June 19, 2012 @10:42AM (#4132037)
Something like this may unclutter the situation, just use xmlhttprequest to get the templates on demand:

    //synchronous
    body.innerHTML = render('blog.html',data)

    //asynchronous
    render('blog.html',data,body)

    render=function(url,data,obj){
        if url in cache: use cache
        var http = xmlhttprequest()
        http.get(url,obj?async:sync)
        http.onready: 
            parse data in html 
            if obj: obj.innerHTML = html
            else: return html
    }
Re:Backbone UI by MatthewPhillips on Tuesday June 19, 2012 @11:10AM (#4132191)
There are work arounds. What we really need is an HTML standard for including templates on a page. Can't we reuse the <link> tag for that?

  <link href="mytemplate.mustache" rel="template" type="text/mustache" onload="showSnippet()" />
Re:Backbone UI by Kilimanjaro on Tuesday June 19, 2012 @12:12PM (#4132594)
I like that, except that templates are used on demand, so onload would be useless. A better way would be to put an id on them and defer their load for when really needed.

    <link hef='blog.html' rel='template' id='myblog' defer>
But still, we don't want to load 50 templates at the same time if the app is big then use one or two in that session, that's why loading them on demand with httprequest might be a better solution.

*Besides, being static in nature they would be cached on the server and client for instant access.

Re:Backbone UI by MatthewPhillips on Tuesday June 19, 2012 @03:09PM (#4133573)
I threw together this gist which does your suggestion: https://gist.github.com/2955953

Use like thus:

  var tmpl = document.getElementById('myblog').template;
Re:Backbone UI by Kilimanjaro on Tuesday June 19, 2012 @03:46PM (#4133752)
Beautiful!