JsServ – Serverside Javascript and DOM emulation

I played around with some ideas about JavaScript on the server-side and came up with this little prototype. It’s a set a spring components that allow running the scripts in a website on the server side in case a user has no support for JavaScript or has disabled it.

The following diagram shows the way things work:

The parts of jsserv

The parts of jsserv

The DOMInterceptor intercepts the HTML output of other controller and initializes a dom state with it. The document itself is parsed into a DOM tree and the referenced scripts are loaded and executed. Additional patch scripts can be defined to alter the behaviour of other scripts.

The current version adds
<a class="eventHelper" href="/app/event?uuid=42">...</a>

Links around every element for which a onclick handler is registered. The links point to a DOMEvent Controller that triggers updates in the user’s DOM State.

A little example scripts implements a collapsable tree that changes the style classes of nested unordered lists. With the JsServ DOM Manipulation this works with JavaScript as well as without JavaScript on the client side.

While this code is only a rough sketch it promises a lot in terms of vastly reducing the amount of work for sites that must use javascript to get an optimal user experience but who cannot or want not to have a java-script only site. Although the link-as-click event method is rather limited, it is good enough to make a lot of DOM manipulations possible. Expressed only once in JavaScript. Running in it’s deluxe form for people with client-side JavaScript and in a basic form for people with the help of using server-side JavaScript. All is seamlessly integratable into all kinds of Controllers.

Links:

Dependencies:

Edit: code.google.com link added, update to 0.12

4 Comments

  1. Hi!
    This project (JsServer: http://code.google.com/p/jsserv/ ) looked very interesting (it is a potential Rhino based Jaxer in my opinion ) but looks abandoned since 2007… is it dead? or did you continue it under another name?
    Regards,

  2. It never got beyond that proof of concept phase.. which somehow is a pity, but I just got no real app to try it on etc.

    I’ve toyed around with server side js a bit, also as CouchDB app thingie, but all too much work for me to really go through with it. (Except for serverside compression/bundling of js based on rhino which plays a major role in OpenSAGA (http://www.opensaga.de/blog/dokumentation/overview/), our soon to be open-sourced work project.

  3. Hi!
    Thanks for answering!
    Sad to read that you could not continue with JsSever…
    DOM manipulation for javascript-less browsers is interesting but the thing about it that interested me the most, was the idea of being able to write client side and server side logic in the same language (as in Jaxer http://www.jaxer.org/).

    The one thing that prevents me form using Jaxer is that I need to have my projects run on Tomcat and connect to the database using JDBC…

    Well, I keep dreaming about a Rhino based Jaxer ;-).
    Regards,

  4. @Luxspes

    Generally, the idea of having the same language on the server and the client side, a common JS context for both the rhino world and the java server world is highly interesting.

    What I am not totally convinced of is extending DOM etc to the server side. While the server side wouldn’t have to deal with the same implementation mess as the client side, there could be a lot confusion and a conceptual bluring of the server/client concept.

    That same kind of murky thinking that makes people try to use PHP function in onclick handlers etc.

    And before we mimic the client side dynamic and have server-side jQuery, Prototype or Moo to replace a server-side DOM implementation that is regarded as too cumbersome from the beginning, maybe there would be a better way to do server-side content-manipulation etc.

    The couchdb app thing I was writing was about such ways.. Basically server-side progressive enhancement by widgets that attached themselves to the HTML doc. But as I said it all became much too complicated to continue side-by-side with the work load of my day job.

Leave a Reply to Luxspes Cancel reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 fforw.de

Theme by Anders NorénUp ↑