Friday, July 6th, 2007
5 Ways to Optimize Ajax in Ruby on 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:
- Optimal Database Indexing
- Eliminate Redundant SQL Queries
- Fragment Caching
- Response Text Compression/Minimization
- 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:











6 – Using another framework and language
7. grab a beer