Live data from Hacker News

Better than templates, building highly dynamic web pages

blog.fastmail.fm

11–20 of 44 posts

Re: Better than templates, building highly dynamic web pages

#13

This reminds me of HAML. I've never really seen the benefit of adding a layer that doesn't really add much onto something that is well-known and thus easily maintainable. Performance benefits seem mostly irrelevant, as pointed out by others.

I didn't see the point of HAML - until I used it. I'm a complete convert now: the syntax is just so superior to being productive in markup for me. In my current app I'm including a small ember app, having to write straight markup for handlebars (hamlbars is a bit awkward) is painful compared to how quickly you can produce markup with HAML.

Personal preference of course, but to me the difference is night and day in terms of my productivity with producing markup.

Re: Better than templates, building highly dynamic web pages

#14

I remember back in the late 90s that generating content on the browser using javascript was the new and greatest thing. Personally it bugs me. But I'm 31, a total fuddy duddy.

Those were the days. I remember coding in Livescript and debating between implementing stuff in VBScript vs Javascript.

Re: Better than templates, building highly dynamic web pages

#15
The DOM is a live object while a string can be sliced and compiled in a function.

If you run a template once, either to generate a form or a simple list, the DOM is faster than innerHTML.

But if you need to repeat a template(loop), use partials or recurse, interpreted DOM manipulations will become a degree of magnitude slower than a compiled function concatenating strings.

Quickly slow enough to loose the snappy effect of client templating.

Re: Better than templates, building highly dynamic web pages

#16
I have a library for this sort of thing (but without the HAML-style # and . niceties :-/) which can also output DOM Elements or HTML (escaped by default) from the same code by flipping its output mode: https://github.com/insin/DOMBuilder

The output modes are implemented as plugins, so you can also add other sorts of things, like the template mode I'm in the progress of writing, with template inheritance and the like.

Bretthopper's comment about the readability is spot on, though - you have to start using comma-first pretty quickly or you will go mad getting commas in the right places, and you're never going to get a designer writing these things.

The good thing about it is that since your templates are written in code, it's trivial to share them between client and server - this example app can also be clones and run on Node.js, which uses the same templates to serve full pages when you hit any URL and works as a forms 'n links webapp if you disable JavaScript in your browser: http://jonathan.buchanan153.users.btopenworld.com/sacrum/fra...

Re: Better than templates, building highly dynamic web pages

#18
post #3

My browser does 10,000 operations / second with innerHTML, and 15,000 operations / second with DOM. In every ajax application I've ever made, this is negligible, compared to latency, server processing time, and downloading time. I guess this saves you 1ms for every 30 elements you create? I'm sure there are some cases I'm missing where this might make more of an impact, but from my understanding of the article, this…

In mobile HTML5 apps _everything_ matters. I spent a significant amount of time building HTML5 apps that mirrored native UI almost perfectly and the primary issue with such an interface was that loading took forever the first time you open the page/app (but was natively-fast thereafter). If you're caching the app offline then JS performance (and moreso CSS performance) quickly become the bottleneck in app usability (because of the huge startup costs of setting up the page on the order of 10 seconds for something your desktop loads instantly).

Re: Better than templates, building highly dynamic web pages

#19
The idea that CSS selectors could be used for element creation is awesome. It would be so convenient to write:

    var link = el("a#top.link[src='http://google.com'][data-external='true']")
Instead of:

    var link = document.createElement('a');
    link.setAttribute('id', 'top');
    link.setAttribute('class', 'link'); 
    link.setAttribute('src', 'http://google.com');
    link.dataset.external = 'true'
Someone needs to bring it to W3C forums, otherwise we might end up with this http://lists.w3.org/Archives/Public/www-dom/2011OctDec/0020....
Post reply on HN