Archive for January 17th, 2011

Server side JavaScript – what’s that good for then?

17 Jan

I used to hate Javascript. All those ugly unreadable DOM manipulations based on getElementById. Yuk.

But then I discovered jQuery and javascript was suddenly not only usable but also fun. I haven’t implemenbted a website since then without using jQuery. There are a few jQuery plugins that I regularly use, typically sliders, calendar clickers, that sort of thing but the real fun starts with coding up your own custom DOM manipulations and interaction layer bells and whistles. In the beginning I would pack all the code into $(document).ready(...) but these days I typically try to generalize the functionality and write a plugin.

But what’s all this fuss about server side javascript? Is it really a language that you want to use to create complex software? I’m not so sure about that. We’ll have to see. Despite my reservation about the prospect of using javascript to implement complex software I have an example where the ability to use in a server environment is at the least helpful and possibly essential.

Recently a collegue asked me to help him a with a problem he was having with a web scraping backend component. Certain information was being scraped form another site that was protected by a login. He had an account on the site so that with a bit of curl and a cookie jar he could fetch the information to incorporate into his own site. The problem arose when the site in question started using a login form that had a session specific identifier that was generated using jQuery after the page was ready. So the curl output did not contain the login form with its session specific login identifier and his POSTs to the login form’s URL were being ignored. This is where server side javascript comes into play. If I can run the DOM manipulation contained in the javascript in the page (and in linked js files) then when all is done I’ll have the login form with session specific identifyer that I need to make the login request.

Now that I think about it the session specific identifier probably comes from an ajax call. All I really need to do is find the call in the page’s linked js files and duplicate it with a curl request and I’ll have everything I need. Ignoring this (probably better) solution I’m going to press on and see what it takes to get jQuery (or whatevery other client site library, mootools, etc) running on a server.

Stay tuned for the next installment…

Stuart McFarlane

Mobile Media Constructs