Marketing Insights and News | Website Magazine: Digital Marketing Tips and Blog

Static to Ajax in Minutes

Written by Pete Prestipino | Dec 3, 2008 6:00:00 AM

It's rare that I'm truly impressed by the "effects" deployed on a website. Well, until now. Nick Van der Vreken created a javascript class that automatically converts a static website into a full-blown ajaxed website. Sounds pretty darn cool, huh? It most definitely is. Nick walks Website Magazine readers through the basic implementation, the customizable animations, and the broader functionalities.

The com.bydust.ajax class is simply a javascript class that automatically converts your static website into a full-blown ajaxed website. Whenever a user visits your website, the class will perform a browser-check. If your visitor's browser is capable of running the needed javascript, it will convert the website automatically. If not, the script deactivates itself and the visitor browses through your website as it is (without ajax request etc.).

The script and how-to van be viewed and downloaded here.

Basic implementation
The implementation of the javascript class is really easy. You just need to add a few lines of code into your pages. These will load and launch the script, and mark the areas you want to refresh on each page. Look at the implementation page on the manual for more information.

Customizable animations
Yes, animations. It's only eye-candy, but it improves both the style of your website and the user's impression of your website.

There are two types of animations available in the script. We have the tweens that smoothly fit content into your page, and the alpha transitions which display content with a nice fade in. As if that isn't enough, these animations are customizable!

There are 13 types of tweens available, from normal easeIn or easeOut tweens to elastic and bouncy. There's also an option to disable the tweens and alpha transitions. This might be good for large pages, since they demand some CPU usage from the visitor's computer.

You can add more eye-candy in the customizable loading-messages, for example, a nice loading image in gif-format or even little flash-movies. By adding CSS-styles in the loading-messages this can be very easy.

Functionalities
It's a bit more than your average, "Hey-I-can-do-ajax" script. With this script you can add event listeners, set up custom rules and custom animations, manage the filetypes handled by the script, and so on.

Attaching event listeners to certain events launched by the script allows you to execute certain pieces of code whenever an event happens, for example, on errors or page loads. Attaching an event listener is very easy. You can attach an event with one line of code. Just like in actionscript, we can use the "addEventListener" function with the same two parameters, the event and the function to execute.

Custom rules allow us to tell the script to discard certain links or forms, or even to only notify the server when a user has clicked a certain link or posted a form. These rules can come in handy when you don't want certain links to be parsed in ajax, for example, feeds or trackbacks. When it's implemented in a Wordpress theme, you'll need to add these rules for the wp-admin folder, feed and trackback links.

Error handling is often overlooked, but not here. The class is able to discover whenever an error occurred and will fix it, when possible. If it notices that there is no way to fix the error, for example, if one of the requested pages doesn't have the information it needs, it will shut itself down and serve the page as a normal browser request, without any ajax. The ajax-class will then load again when the new page is fully loaded. If the script is able to fix the error, an error-event containing all information will be raised and an appropriate message will be shown. These messages are also customizable.

Webpages often contain images. That's why I've built in some image preloading functions. When the ajax-class receives the new page from the server, it starts looking for images in the content areas that need to be refreshed. As long as it's preloading, a (customizable) message will be shown to the user. When the images are fully loaded or the maximum load time has been reached, the script will display the page. And, as you can guess, the maximum load time can also be specified by the user.