AJAXed website - Automatically convert to AJAX website - com.bydust.ajax
October 17th, 2008
AJAX, Browsers, CSS, Javascript, Noteworthy, Projects, Themes, Wordpress
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. ).
You can download the script and view the howto at http://www.bydust.com/examples/com.bydust.ajax/
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 area’s you want to refresh on each page. Look at the implementation page on the manual for more information.
Customizable animations
Yes, animations. Its only eye-candy, but it improves the style of your website alot, and the users impression of your website.
There are two types of animations available in the script, we have the tweens who smoothly fit your content into your page, and the alpha transitions which display your content with a nice fade in. As if that isn’t enough yet, 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 visitors computer. Don’t think you’ll need to disable tho :)
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
Its 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 ( but offcourse these never occur :) ) 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 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 occured, 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 down itself 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 offcourse :)
Webpages often contain images, thats 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 its 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.
Since this is a pretty big project I’ve set up a small howto-website with loads of information about the script, and an example for you to download. You’ll find a detailed manual for the basic implementation there, along with the more advanced stuff.
The script is completely free for non-commercial use, but I’d like you to leave the credits in the classfiles and maybe a small link back to this page - if its not too much trouble. I’ll link back to your website if you’re using the script, so others have some more working examples. Contact me for commercial use :)
Com.bydust.ajax has been featured on several websites and communities:

There are 204 replies to this item:
February 15th, 2010
Erik says:
Hi…
I just posted my clients website with your ajaxed framework and I’m getting complaints the website is “showing up as text” at first and appears correctly after a refresh”. I myself haven’t seen this problem yet, but other viewers are.
I am puzzled…
The only reason I can think, I’m still posting the website through a sub domain for designing purposes.
Could everyone take a look at this and see if the same problem occurs?
http://www.naturalskin.com/ras/
Many thanks.
Cheers,
Erik
November 23rd, 2009
Caillou says:
This is a very or js. I enjoyed it. I’m trying to put it into wordpress theme but it does not work. You can help me? This is my Gmail.
November 20th, 2009
Jim says:
Hi Nick,
Just wanted to thank you…
My whole website is now done, with additional api’s , like google search,translate, ive written em in jquery….
Hope you like em…
check it out here http://www.jobstriker.com
Thanks for this…appreciate it!
Regards,
Jim.
November 15th, 2009
Nick says:
Hi Travis,
the content is replaced because wrapping divs are added, in order to animate and replace the content. Links are also changed so they’d work with AJAX instead of the regular browser functions. (but this is done through the DOM, has nothing to do with the replacement)
Cheers,
Nick
November 12th, 2009
Travis says:
Hi Nick -
Great script. I was curious why, in the initialization of the script, you are resetting the content of the primaryRegion with its own innerHTML content (line 159). Is the purpose of this to strip any previous event handlers from that content area that might conflict with your AJAX controller?
Thanks,
Travis
October 30th, 2009
Nick says:
Hi Maicol,
if you need to trigger the AJAX via flash you can use some built-in classes to talk from flash to javascript (google). The getURL() function from Flash allows you to call HTML pages too as Sharon said.
Sharon, thanks for the help :)
October 30th, 2009
George says:
Thanks, it worked.!
October 30th, 2009
Sharon says:
Hi George,
Im sure Nick(the author) appreciates you like the script.
I just tested it, YES! IFrames do work and get refreshed.
You can add it to the refresh div, or in main content area.
It will reload the HTML of the iframe within the div.
No Javascript within iframe.
However, the html you are calling within the iframe, may have javascript, it does not need to be parsed, it is just called.(reloaded)
Hope this helps!
If Im wrong, im sure Nick will correct me :)
Regards,
Sharon.
October 30th, 2009
George says:
Hi Nick,
Can we use iframes in the main content area with your code.
Would it parse the data and refresh it.
Actually, i have already implemented your script, and uploaded it to my website, i dont want users to see a faulty page while i test if it works.
Thanks for the script btw. :)
George.
October 25th, 2009
Sharon says:
Hi Maicol,
As per my knowledge about flash, which is very limited, there is a “action” event to be specified for links.
which is something like this:
on(release){
getURL("http://www.mysite.com", "_blank")
}
Firstly, use the full url(http://www.mysite.com/xyz.html), then make the target, _self, instead of getURL try bda.getURL.
Also, if you say its not working, also add what all you have tried.
Basically, I don’t think the ajax script can read into the flash, so it looks at it as an outside link.
You can also try
getURL(bda.getUrl("http://www.mysite.com/xyz.html"))
Please post what all you have tried, what you have found, what works partially, if at all.
Regards,
Sharon.