Page 1 of 1
Learning AJAX/Javascript best practices
Posted: Sat Apr 14, 2007 7:19 pm
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).
Posted: Sun Apr 15, 2007 2:43 am
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.
Posted: Sun Apr 15, 2007 4:11 am
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.
Posted: Sun Apr 15, 2007 9:39 am
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.
Posted: Sun Apr 15, 2007 9:59 am
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.