Tuesday, July 10th, 2007
JavaScript running to the server
<>p>JavaScript continues to get more talk on the server (yes, years after Netscape Enterprise Server!).John Resig spent a weekend hacking in the zone, to bring the browser to the server.
This resulting environment allows you to do interesting things such as:
Screen scraping
- load("env.js");
- window.location = "http://alistapart.com/";
- window.onload = function(){
- load("dist/jquery.js");
- print("Newest A List Apart Posts:");
- $("h4.title").each(function(){
- print(" - " + this.textContent);
- });
- };
Web Framework
- window.onload = function(){
- print("Content-type: text/html\n");
- if ( location.href == "/" )
- show_home();
- print( document.innerHTML );
- };
- function show_home(){
- document.load("index.html");
- document.getElementById("time").innerHTML = (new Date()).toString();
- }
Tom Insam and Ash Berlin also created mod_js, which is a very simple JS embed. Others pointed out mod_wxjs, haxe, and the like.
The beat goes on.
Related Content:











The same is the very core principle of http://www.widgetplus.com and the widgets there, which are all database driven serverside widgets, and the coding behind them – on the server – is javascript and it’s mimicking the browsers DHTML enviroment almost o the letter.
The guys over at http://www.wxjavascript.net have a mod_wxjs Apache module which gives you the server-side Javascript. Also, http://www.whitebeam.org has a whole Javascript-based server-side environment.
In any case, I personally prefer SpiderMonkey implementations to Rhino ones.
simile is using a headless firefox as a server, for its crowbar scraper daemon. with the existing serverside JS stuff sucking ( i mean, writing JS in JAVA is just not fast, sorry..) and Tamarin coming, it will be neat to see this concept mature to the point of more robust usability
The problem with haxe is that its JavaScript implementation is ActionScript 2.0-ish, being heavily based on the concept of classes. To quote a quote from bash.org, ActionScript is like C#, Java, and Visual Basic had a threesome, and did not use protection. I personally find ActionScript less refreshing than JavaScript.
@kourge:
It may be a little uncomfortable seeing actual class stuff coming in to the picture – but without it people are going to have a really hard time finding good counter arguments to :
http://beust.com/weblog/archives/000454.html
for bigger enterprise-y type projects. Maybe that’s not where it should be used (js2), but if it works it sounds potentially kind of fun..