Live data from Hacker News

Simplify templating with node.js, jsdom 0.2.0 and weld

blog.nodejitsu.com

11–20 of 20 posts

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#11
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

I'd have to agree with you, for most traditional web applications.

When you start to build single page applications with lots and lots of states ( that are bound to a DOM ), this approach actually can become favorable since your "presentation logic" is browser-side JavaScript.

To my understanding, the server-side rendering aspect of this approach is really just an after-thought. You have your single page application, but you can still render a server-side snapshot of various UI states without requiring a browser.

While I wouldn't necessarily dive straight into DOM-based templating, I think there is a lot of room for interesting improvements in this area. I'm glad to see JSDOM maturing.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#12
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

Also it's probably worth to mention that manipulation of DOM is not that fast. Every performance optimization article starts with "don't manipulate DOM directly, make a batch of your changes and then inject them in one step".

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#13
post #12
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

Also it's probably worth to mention that manipulation of DOM is not that fast. Every performance optimization article starts with "don't manipulate DOM directly, make a batch of your changes and then inject them in one step".

I don't see any reason for JSDOM in the server to be slow, the object tree being manipulated isn't all that complicated. They aren't suggesting the typical mess of putting useless markup on the wire and then conducting massive repairs to it in the browser's DOM, all while a rendering engine tries to repaint each change.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#14
post #3

The Enlive system (for Clojure, see https://github.com/cgrand/enlive ) does something very similar.

Yes its nothing new. You can find lots of modules/libraries that have been around for quite that do same/similar things.

Here is a list which was put together & called "Push style template systems" which covers some of these modules/libraries (in different languages): http://www.perlmonks.org/?node_id=674225

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#16
post #12

Earlier quoted context omitted.

Also it's probably worth to mention that manipulation of DOM is not that fast. Every performance optimization article starts with "don't manipulate DOM directly, make a batch of your changes and then inject them in one step".

I don't see any reason for JSDOM in the server to be slow, the object tree being manipulated isn't all that complicated. They aren't suggesting the typical mess of putting useless markup on the wire and then conducting massive repairs to it in the browser's DOM, all while a rendering engine tries to repaint each change.

Seems like the complexity of the client-side code comes from rendering the DOM tree based on the CSS and constraints of the drawing area, hardware, etc. So yeah, just manipulating the tree would seem to be pretty fast.

Of course, it's being compared to spitting out an arbitrary stream of characters to the client without the need to parse HTML on the server side, which is probably faster. Years of experience with the string rendering approach tells us it's definitely more error prone. For example it's impossible to tell whether the character stream is well formed HTML without traversing all the code paths.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#18
The fact that it's all std-based, and back/front-end rendered is beautiful, but what seriously bothers me is how much weld.js is tied to jQuery.

The README states "Use with whatever library you want, jQuery for example". Let's analyze that for a second.

Weld.js uses the following jQuery methods: - Sizzle selector ($) - first() - is() - val() - attr() - text() - map() - extend() - clone() - data() - remove()

These methods are used throughout the 249 lines of code.

This makes weld.js completely dependent on jQuery. Thus, you can't just use whatever library you want. And that would be allright, if the README would say that; but it didn't, and so it isn't.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#19

The fact that it's all std-based, and back/front-end rendered is beautiful, but what seriously bothers me is how much weld.js is tied to jQuery. The README states "Use with whatever library you want, jQuery for example". Let's analyze that for a second. Weld.js uses the following jQuery methods: - Sizzle selector ($) - first() - is() - val() - attr() - text() - map() - extend() - clone() - data() - remove() These met…

meh, we might remove jQuery next version.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#20
post #12
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

Also it's probably worth to mention that manipulation of DOM is not that fast. Every performance optimization article starts with "don't manipulate DOM directly, make a batch of your changes and then inject them in one step".

that's subjective (unless you can post tests). for example, one of the primary deficiencies of the dom is live node lists, which is an optimization option in jsdom. (also, we do create a fragment and then attach, as perf opts state)
Post reply on HN