Friday, July 6th, 2007

5 Ways to Optimize Ajax in Ruby on Rails

Category: Articles, Rails

You’re understandably proud of your latest fancy Ajax interface, but is it wasting your app’s precious resources? In this article on Think Vitamin, Shanti Braford shows you five ways to make sure your Ajax is optimized.

He goes into detail on:

  1. Optimal Database Indexing
  2. Eliminate Redundant SQL Queries
  3. Fragment Caching
  4. Response Text Compression/Minimization
  5. Pre-rendering and Client-side JavaScript Caching

You will note that most of these have little to do with Ajax, and are general advice. It gets interesting on:

5. Client-side JavaScript Caching and Pre-rendering

If you really want to wow your users, pre-cache commonly called AJAX components into hidden divs so that the only time necessary to load them is the time it takes their browser to execute (eval) the pre-rendered JavaScript.

In the following example, we’ll cache conversations into hidden divs so that whenever a user clicks on a conversation, it’ll load almost instantaneously.

The pre-caching functions will all access a single global JavaScript variable that holds an array. That array will be populated on the first page load with the conversation IDs that should be cached.

Posted by Dion Almaer at 5:20 am
2 Comments

+++--
3.4 rating from 27 votes

2 Comments »

Comments feed TrackBack URI

6 – Using another framework and language

Comment by Tio Malandra — July 6, 2007

7. grab a beer

Comment by Bob — July 9, 2007

Leave a comment

You must be logged in to post a comment.