Implementing HTML DOM rewrite logic on the server

My application does bulk rewriting of the client-side DOM at boot time. He scans the page for special markup (think Markdown) or other templates, sometimes replacing them with fairly complex DOM structures (using DOM calls like createElement ) to style text and create charts and graphics.

I adopted this architecture to avoid any assembly steps or preprocessing. It works great in a desktop browser, but is noticeable on mobile devices (a few seconds, even after tireless optimization). So I would like to rebuild the system to pre-scan the page and pre-build the DOM. I have a little mental block that figures out how to do this. Obviously, I would prefer not to rewrite all Javascript in some other server language. In addition, I would like to keep the ability to make the building at boot time, as it is now, while the basic rewrite logic uses the same code.

The most likely option is to create this as a node application, although I'm a newbie to node. using jsdom both for parsing input and modifying the DOM. Or, since I'm a fan of XSLT and intrigued by Saxon-CE, although that would mean rewriting everything, I also considered using the scan / rewrite logic in XSLT to call either from node (for the pre-construction case - do people use Saxon from node? ) or a browser (for the case of building load times).

Can someone comment on this approach or throw away alternative ideas?

+3
javascript dom saxon
Oct 02 '12 at 3:15
source share
2 answers

You don’t know what specific use cases you decide when bulk rewriting the DOM, and I'm not sure what your bandwidth requirements are. However, one alternative approach to the node / jsdom route might be to start a farm of Webkit headless browsers and run your current JavaScript as it is in the context of real rendering. This will allow you to overload processing from these pokey mobile processors into arbitrarily scalable cloud resources (provided that it may be available for your project / business) and bypass the need to rewrite or configure the current current working code.

+3
Oct 02 '12 at 4:12
source share

Looks like you want Node. If you already know that this is really a cinch to pick up.

I would recommend a tutorial like this: http://www.nodebeginner.org/

It takes you an hour to go through, but gives a complete overview of Node when you create a small but functional application with the author.

0
Oct 02 '12 at 3:16
source share



All Articles