Sunday, March 11, 2012

Server side JavaScript

I really do not like the idea to use server side Java Script. In fact I am really hating Java Script even on the client side. I everytime worked arround even the client side one by using the GWT framework. (GWT allows you to write Java code which will become translated to JavaScript. So my question was "Why the hell should anybody like to have server side Java Script?". There two different answers from two different perspectives:
  • As a Developer for Alfresco, you just need (not really you can also use the more complicated Java API) to know that it is existent, because they invented something which is called WebScript.
  • Because it is interpreted code, it is really more flexible. So you can just change it on runtime. A JavaScript engine then is used to just execute your code. Such an engine is E.G. Rhino

A WebScript is just a JavaScript file which can be accessed as a RESTFul service. It sets some output model which is then used together with a Freemarker template to generate the response. So it is following a Model View Controller concept. The WebScript takes the role of the controller. It has access to a model. A freemarker template is used for the View. (This could be HTML or just JSON or plain TXT) A WebScript has access to Alfresco-s JavaScript API. ( So it can access content by providing some output (E.G. the content properties as XML). The advantage is that you can just deploy content oriented RESTFul Web Services without the need to restart your Servlet-Container or Application server. Alfresco is using it quite often, even for their Share-Dahslets. Meanwhile it also became added to the Spring Web-Framework (

Rhino is a JavaScript engine which is implemented in Java. You can just use it to extend your own Java application to support JavaScript. Further information are available here:

What's your opinion about server side JavaScript? Just give me some comments!


  1. Mmmh, have to think about it ... .

  2. I'm personally not a great fan of JavaScript. Thankfully things jQuery makes it bearable. The great plus of JS is of course the client platform independence.

    However, platform independence is not necessarily a killer criterion on the server, as the number of platforms on the server is usually exactly one.

    But there is one use case, I can think of, where it makes sense and that is user input validation. If you can use the same code base to validate input on the client side and then again on the server, you save half the work.