Activate your free membership today | Log-in

Friday, July 6th, 2007

5 Ways to Optimize Ajax in Ruby on Rails

Category: Articles, Rails

<p>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.

Related Content:

  • Ruby on Rails update aims at Ajax
    Ruby on Rails 1.1 offers RJS as an alternative to JavaScript for coding Ajax applications. "It's the perfect antidote for your JavaScript blues,"...
  • Ajax on Rails
    In this interview Ruby on Rails creator David Heinemeier Hansson, he talks about how Ajax has become part of its "full stack" in the new Rails 1.1....
  • Investors on Rails
    Ruby on Rails is attracting investors, as Benchmark Capital, an early backer of eBAY announced this past week that it is investing $3.5 million in...
  • Hot skills: Ruby on Rails 2.0
    Rails is not the only framework for Ruby, and Ruby is not the only language which uses Rails. Rails has also been ported to Javascript by a team at...
  • Here comes Ajax on Rails
    Moving toward a convergence of Ajax development with Ruby on Rails, Aptana Inc. is including the Ruby Development Team project in its IDE for Ajax...

Posted by Dion Almaer at 5:20 am
2 Comments

+++--
3.5 rating from 22 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.