wesley tanaka

AJAX?

‹ That's a lot of money! | Key copier ›
()
AJAX is an acronym dreamed up by some dude. It expands to "Asynchronous Javascript and XML", which are 2 concepts which have been around roughly since Netscape was relevant and 1 other concept that has been around forever. Just shows that coming up with a memorable new name at the right time can cause a lot of people to start using it.

Anyway, I wrote a chat room. Like all chat rooms, it has asynchronous aspects to it. It happens to use Javascript. Not only that, in order to work around some ridiculous inconsistencies in the XMLHttpRequest object, I was forced to even use XML.

While writing the chat room, I've noticed a pattern. I don't mean pattern in the sense of "Design Pattern" -- the word that so many people seem to be misusing and otherwise abusing these days, but just the normal generic "pattern". Code that needs to be written (in my case in PHP) on the server also needs to be written in Javascript and made available to the browser. As a means of explanation, let me describe a few concrete examples from my chat application:

Example 1: I am using a slightly modified version of this lib_filter library to filter out potentially annoying, broken, or otherwise malicious HTML tags and elements before they appear on the screens of other chatroom inhabitants. Since anybody can send whatever HTTP requests they want directly to the server, this filter needs to be run in the server. However, the chat room also features a preview field. While it would be possible for the server to continuously filter the user's message as they were typing it, a better solution would be if the same filtering logic were available in javascript so that the browser could filter the text in exactly the same way, without using any bandwidth at all.

Example 2: I replace textual "emoticons" like "=)" or "=(" with an image. The replacement code needs to be implemented on the server so that when you first load the chatroom page (with or without javascript), the smileys are there as images. However, the replacement code also needs to be run on the client when new messages are downloaded from the server. The alternative is to replace the smileys in the new messages before they are sent to the browser, but my way saves bandwidth, which is going to be a big problem in any current-day Javascript chat room.

I remember reading somewhere that Netscape's web server (back when there was a Netscape) allowed you to write your page-generation code in Javascript. This suggests a reasonably good path-of-least-resistance-way to deal with this "problem" that I'm having:

1) Write a big, standard, library for Javascript that duplicates all of (say) PHP's useful functionality, including string manipulation, database connection, cookie and session handling and whatnot.
2) Create and standardize a small extension to the Javascript language that looks like PHP, or ASP, or JSP. <?JSSP /* javascript code goes here */ ?>. Include in these extensions a few meta-directives like "include". For the next few paragraphs, let's call this extension "JSSP"
3) Make an Apache module that parses and runs JSSP in-process, like the PHP module does.

Now I can write Javascript code that gets included into my JSSP pages, and also included into my HTML documents in the normal way. Modifying the code modifies both the server logic and the logic used by the browser at the same time.

There's probably things out there that already do this or similar things. Feel free to write a comment if that's the case. I just haven't bothered searching google yet.

Suggested Links

Javascript for server-side development

I think you will love OpenMocha and Helma. OpenMocha is a web development framework based on Helma, a full-featured server-side Javascript environment. I do in OpenMocha exactly what you are describing, reusing server-side Javascript libraries on the client side and vice-versa.

http://openmocha.org/
http://helma.org/

Both projects are open source.

Chris
chris@czv.com (mailto:chris@czv.com)

Re: Javascript for server-side development

The openmocha site sure is full of buzzwords.

Helma sounds interesting, but I'm really just talking about something scriptable -- "less than well-designed and maintainable," as the Helma site puts it. Just something "worse is better".

JavaScript Templates

You might want to check out JavaScript Templates

http://trimpath.com/project/wiki/JavaScriptTemplates

The other trimpath libraries are very cool and useful too..

Re: JavaScript Templates

Not the same as what I was trying to describe. Looking for something more capable, and with braindead syntax like PHP. I like braindead syntax, and it would be easier for existing "Web Developers" to learn.

AJAX Chat download

Hi Tanaka,

i very want download this chat (http://treehouse.ofb.net/chat/?lang=en) is possible? is opensource? I'm web programmer and developer and will like get this source......i think this chat very good.....

i wait your return...regards

Luís Felipe Richter
msn_sor-messenger@yahoo.com.br

WhiteBeam+SpiderMonkey

SpiderMonkey is an Open-Source implementation of JavaScript. Actually, it was the original implementation of JavaScript even for client-side, the original implementation of Netscape, and Firefox/Mozilla are based on it. So don't be afraid that this is a non-standard implementation with compatibility issues: Actually, it IS the standard implementation of JS (or may I say "the reference implementation"?).

Contrary to Rhino, it's based on C, so it's faster.

WhiteBeam (http://whitebeam.org) is doing exactly what you are looking for: It is combining SpiderMonkey with Apache, adding a special JS module to Apache, and other features that allow it to function as a full replacement for PHP and ASP.

Moreover, WhiteBeam adds XML support and other goodies, that make it a real web application server, but I'm afraid that this exceeds your needs, and makes it an overkill.

But you can still use the more basic features of WhiteBeam, which are the exact answer for your needs.

I'm still looking for a project to build a pure implementation of SpiderMonkey module for Apache (preferred - Apache 2.2), without the whole stuff around. Of course - with compilation (to save overhead). PostgreSQL integration may be a good idea.
--
Eli Marmor

Re: WhiteBeam+SpiderMonkey

It didn't look like they had a database API going yet. With a bigger standard API, I think it would be great.

Re: WhiteBeam+SpiderMonkey

Have you seen this page?

http://whitebeam.org/library/guide/TechNotes/postgres.rhtm

Or you mean that this is not enough?

Thanks!

Re: WhiteBeam+SpiderMonkey

I looked for information about the standard libraries in the "Reference" section instead of the "Tutorial" section.

Download

Sir, is there going to be a download for that slick chat app you have going on?
Thanks

Re: Download

Interest in it does seem higher than when it first went online. Though the defacto plan is no, that might change if I get back around to working on it.

firecat Webserver

firecat is server-side JavaScript Webserver. It uses JavaScript in a straight forward manner, much as ASP uses VBScript. Doesn't get anymore brain dead than that. http://firecat.nihonsoft.org (http://firecat.nihonsoft.org)

Re: firecat Webserver

Looks like an interesting project. An apache module would have a much higher chance of getting adopted than a stand-alone webserver though.

Syndicate content