Learning AJAX/Javascript best practices

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Learning AJAX/Javascript best practices

Post by Maugrim_The_Reaper »

I had a look over two applications I made some time ago which used AJAX and realised something was amiss - the Javascript didn't seem all that well organised - it was really little more than a spaghetti collection of functions and objects. I was wondering if anyone had found a truly brilliant resource (site, book, other) which does a good job of explaining how to organise AJAX/Javascript using design patterns to reduce duplication, introduce a framework like structure, and obviously keep the javascript documented, tested, and maintainable.

I had a look at the current AJAX material I have, and I realise none of them approach the subject (and half seem to work a simpleton XMLHttpRequest wrapper anyway).
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Bulletproof Ajax from Jeremy Keith is a very good book. He is a big proponent of unobtrusive scripting, using best practices and using the principle of progressive enhancement. That means separation of the different layers. You can download the code and an example chapter on the website to see if the book is anything for you.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

jQuery has some nice ajax functions on the javascript side of things.

On the server side, I recommend going through the same MVC spanking machine you would for any other page and returning a JSON / XML response instead. That way your MVC is intact, and your security / authentication doesn't get by-passed.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

I'll check for that book, matthijs - sounds good.
On the server side, I recommend going through the same MVC spanking machine you would for any other page and returning a JSON / XML response instead. That way your MVC is intact, and your security / authentication doesn't get by-passed.
Not speaking of the server side - I already maintain the PHP within an MVC framework that's RESTful. Security shouldn't be compromised from that angle (once you pay attention to the javascript specific weaknesses at least). It's the client side organisation of javascript that interests me. Just like my PHP follows distinct patterns, organisation, conventions etc. - my javascript should follow it's own somewhat similar ideals. I've been a bit lazy using AJAX which only needed a few function callbacks (less than 20) and never was all that reuseable - in something bigger that will quickly become unmaintainable and duplicative. I've found very hard to dig information like this up on the web - there is too much noise hiding what I need.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

http://www.sitepoint.com/books/ajax1/

Matthew Eernisse put together a good teaching on OO Javascript right from the start. In fact, the first javascript code he puts together is a OO Ajax library.
Post Reply