Hijaxing
I have been working on a website that uses Ajax calls to dynamically load content into the same page with out refreshing. One of the reasons Ajax was chosen was to create a user experience similar to a flash website. The site appears very smooth, and is as close to a flash site that I have ever built.
As I was building the site I actually started off building the pages as I normally would, as individual pages that linked together. I had the whole site working as a regular website before adding in any Ajax. What I discovered as I added in the Ajax and started browsing the site was the site was still accessible to users without javascript turned on. This also means that the whole site is also accessible and readable by the search engine spiders. This was fantastic news, since one of the downsides of using Ajax is that the search engines do not index the content that is loaded through the Ajax calls.
When I realized what I did I was certain I was not the first to discover this, so I did some searching and discovered all about Hijaxing. There are several elements that I discovered are key to Hijaxing a website.
- Plan to use Ajax on your website from the beginning.
- Build your site without Ajax. By building your website without Ajax at the beginning you will create the links just like you are building any other website. You will also remember to do any server side error checking that you might otherwise forget.
- Once the website is complete and functional without Ajax add in your Ajax calls and javascript to dynamically load your content.
It is important to use javascript event handlers to hijack the regular browser request and simply return false when it completes to stop the browser from completing the normal browser request. For example, a link to a new page might look like this: New Page Here the browser will carry out the Ajax function specified in the onclick event handler, and because false is returned the browser will not actually follow the link to a new page.
Hijaxing makes the creation of Ajax enabled sites more attractive since the sites will still be accessible by users browsing with javascript turned off or with text based browsers (they do still exist). It also benefits a websites search engine marketing by allowing it to be indexed and having more than the index page included in the search engine results pages.
Comments
Andy Bailey
that's really useful to know, I'm planning on putting ajax into one of my sites and this will help a lot thanks!
LGR
Thanks! I see you have a series on AJAX on your blog. I will have to take the time to read through it.