Eric Falcao has released Clientperf, a simple client-side Rails performance plugin.
The tool came about as Eric is giving a talk on “14 rules of high-performance websites in the typical rails mongrel/nginx stack, the main idea being to focus on some of the important implementation details when it comes to client-side performance optimization.”
As I was planning, I realized that there was no simple as in the we’re-all-spoiled-with-rails simple way to measure client download times in production. Now, there is clientperf. It’s just a start, but decent enough to benchmark the actual client performance impact of any optimizations you make.
How it works
It injects javascript into the page that takes a timestamp at the top of the page and at the bottom of the page. Once the browser is done downloading, evaluating and rendering all assets, clientperf makes one last image request to your server with the start time, end time and the URL. Piece of cake.
Aptana took over the RadRails open source project a few months back, and now have fully integrated it with Aptana Studio with the RadRails 1.0 release.
RadRails 1.0 runs as a plug-in to Aptana Studio. So in addition to all the Ruby on Rails IDE goodies and the integrated Rails shell command-line console, developers get the great HTML, CSS, DOM, JavaScript and Ajax features in Aptana Studio, which can run stand alone or within Eclipse to that all your other Eclipse tools can be right there as well.
The new version has a slew of new and enhanced functionality such as:
Rails 2.0 support
JRuby support
Bundled auto-installing gems for rails development
A Ruby profiler for Pro users
An RDoc preview view
Extended RHTML/ERb color preferences
Code completion for ActiveRecord model fields and finders
Code completion suggesting method call arguments
Significant expansion of code warnings and analysis, including syntax changes from Ruby 1.8 to 1.9
Heroku is a new YCombinator startup that joins the growing number of “use your browser to build your apps” type of applications.
You can create new Rails applications, and they are magically hosted up in the cloud. You can import your own Rails application, or you can use the inline editor and tools to built the application directly in the browser.
Heroku itself is a Rails application. I wonder if they now self hosting :)
Being able to quickly build an application and have it running live is great (using Amazon EC2), and this is just the beginning. They already tie into the usual tools like Rake, but there is room to go further and have nice DB utilities, cloning of functionality, and much more.
The editor itself could use a bunch of work too. I can never see where the cursor is, let alone have all of the Textmate / Aptana / IntelliJ goodness.
Last week we posted about Jaxer which offers an approach of turtles all the way down where JavaScript is used on the client and the server.
Then, I got to interview Steve Yegge. Last year, Steve posted about Rhino on Rails, his port of Ruby on Rails to the JavaScript language on the Rhino runtime.
What can’t you do since JavaScript doesn’t have the same meta programming facilities?
Rails = a group of Active*, so did you re-implement everything?
What do you gain out of having JavaScript all the way down?
Does it actually make sense to have jjs? Server side JavaScript generating client side JavaScript? Argh!
What is the state of Rhino?
Will Rhino support JavaScript 2?
And of course, the big questions:
When do I get to see it!
I happen to be in Seattle at the Google offices, so I was able to ask all of these questions and more. Steve was a fantastic host, and I really enjoyed chatting with him.
This is the kind of video I want to explore at Google. We have many great developers working on cool technology. I want to get them on camera, participating with the community when I can. Sometimes we can talk about products and APIs, but sometimes we will talk about fun ideas and projects that we are working on such as Rhino on Rails.
Anyway, give it a watch and let me know what you think:
The Ext Scaffold Generator Plugin provides a custom MIME type alias :ext_json to be able to handle requests from the Ext frontend separately. The generated controllers show how to do this.
To make data delivery to the Ext frontend easy, the plugin extends the Array and ActiveRecord::Base classes to provide a to_ext_json method. Here’s a simplified example of a potential index method in a PostsController:
# GET /posts
# GET /posts.ext_json
def index
respond_to do |format|
format.html # index.html.erb (will fire ext_json request)
format.ext_json { render :json => Post.find(:all).to_ext_json }
end
end
He also has some other good articles on integrating Ext JS and Rails in general.
I was at the PCWorld innovative product awards at CES last night, and ran into Tastebook, a site that allows you to build a personal cookbook from both online and your grandma's recipes.
The site is Rails based, and uses a mixture of JavaScript and Flash to get rich functionality such as a visual representation of the book, a designers, access to Web services, and drag and drop support.
Rob Sanheim sat down with Zed Shaw at RailsConf and had an hour long conversation with him that covered his thoughts on the Rails community, the role of the Enterprise, the state of Ajax, JRuby and Rubinius, documentation, tests, tooling, the role of patents in software, and a whole lot of opinion.
It is very interesting to listen to this after the explosion that happened when Zed lambasted the Rails community. When you listen to this interview, you see some of the seeds of the rant, but it is a lot more toned down, and there is some good stuff in there. It is easy to blog a crazy rant.... but when you are talking to someone you get a different side of the coin. This gives you that side, from a time when he wasn't as upset as he may have been when he sat at the computer to type up his post.
Derek Gaw gave an ignite talk tonight onAIR which showed off his Uncluttr project.
Derek works for Amazon, but this is outside of his company work. He is frustrated seeing 1.5MB of content being downloaded when you login, find a book, and then view the detail page. That is too much.
Uncluttr uses the Amazon Web Services and is written with Prototype and 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:
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.
RailsConf is underway in Portland, Oregon, and day one (Friday) is in the bag. The keynote by DHH covered what to expect from Rails 2.0. Front and center was an emphasis on RESTful development, which should come as no surprise to anyone who has followed Rails lately. The big takeaway for ajax developers is that Rails will let you return javascript seamlessly for any request, right along side the same code you use for a standard HTTP requests, or XML requests, or whatever. This ultimately means more cohesive, cleaner code in your controllers, and that adding ajax is as easy as adding a format.js to serve XHR requests:
class PeopleController <ApplicationController
...
def create
@person = Person.create(...)
respond_to do |format|
format.html { redirect_to person_url(@person) }
format.xml { render :status => :created, :location => person_url(@person), ... }
format.js {
render :update do |js|
... # RJS code here to update the page with js with your created person
end
}
end
end
end
Rails 2.0 also has some great optimizations coming for HTTP performance. If you've ever looked at the size of prototype+scriptaculous (or dojo, or yui, or...), plus your own custom scripts, PLUS the overhead of the HTTP connections for each seperate javascript file, you know that page load time can get horrendous really quick. The upcoming version will allow easy batching of your js and css, and automatic gzipp'ing when in production, using the standard javascript/stylesheet include tags:
One other quick win Rails 2.0 will give you is multiple hosts for assets. Browsers will only have two concurrent connections open for any single host, but an easy way around that is to use multiple subdomains that resolve to the same domain. So if you set:
Your rails app will randomly choose static01, static02, etc...to get more parallel connections for static assets. This assumes you use the built in img, js, and css helpers, of course.
For more full coverage of the keynote in core-Rails areas, see Nick's notes.
The other ajax-centered session for the day was on full web stack testing with Selenium Remote Control, by Alex Chaffee and Brian Takita (PDF here). The ajax testing story is still a mixed bag, with a lot of different tools and approaches and not one clear best path. Selenium RC lets you test at the function level of your JS, all the way to a functional level of forms and events, all in the language your app is written in (hence the "remote control" part). For more details see the Selenium link above or the detailed pdf for all the code.
The Aptana IDE is targeted at AJAX (Asynchronous JavaScript and XML) style development and provides support for JavaScript, CSS (Cascading Style Sheets) and HTML and is fully integrated with FireBug for JavaScript debugging. The Aptana IDE is cross-platform, open-source, and free; with the addition and integration of RadRails and RDT, the Aptana IDE will make "Ajax on Rails" a reality, company officials said.
I have been trying out Coda on the Mac, and it is pretty nice for mainstream Web development.
CrowdRules is a Ruby on Rails website that lets the community rank videos.
Igal Koshevoy told us about the new site that is in beta:
CrowdRules is a "crowd-powered content recommendation engine". We use Ajax in a few, carefully-selected parts of our application to improve the user experience. Our application is written using Ruby on Rails and implements Ajax features using RJS templates and the Prototype library. These tools are a pleasure to work with and make it easy to get things done right, so we highly recommend them.
Here are some of the highlights of our use of Ajax:
Votes and violations: CrowdRules strives to provide a honest voting environment for our users. The application prevents common abuses of online voting systems by encrypting votes using one-time tokens. Ruby on Rails lets us elegantly bind the voting UI with the logic that manages tokens and thus votes. In the past, using AJAX meant struggling with parameter parsing and writing screenfuls of JavaScript that often duplicated application logic or required a bunch of stubs to interact with the underlying application. But Rails lets us implement the voting features without any of that fuss. Using Ajaxified Rails helpers, like "link_to_remote", the user clicks are cleanly routed to our controller for processing and then onto an RJS template that generates JavaScript to update the UI. The resulting code is surprisingly easy to read and maintain. The same pattern is used to let users report violations such as "this video doesn't play".
Video creation: CrowdRules tries to make it easy for users to add exciting content. We use AJAX to save users from having to fill out long forms that specify the video's name, embed HTML and such. Instead, our users simply paste a video's URL into a form that invokes an Ajax-enabled action that parses it, identifies the media provider (e.g. YouTube) and uses that provider's API to return a pre-populated form automagically. The form only displays fields the user needs to fill out, which vary depending on whether the video was found, was already in our system, what provider serves it, etc. When the user submits the form, all fields are validated against rules unique to that state and this prevents broken submissions by making sure that the embed HTML matches an actual video at the media provider, that the entry has a title and so forth. The combination of AJAX bindings, Prototype, and Rails features like ActiveRecord validations let us make this friendly form quickly.
Unit tests: It's important for Crowdrules that our application works correctly, but this can be a challenge for a rapidly-growing application that we're always adding features to and even a small change can inadvertently break the system. To address this, we've built an automated test suite that validates almost all of our application's features. AJAX is tricky to test, but we've made the AJAXified actions fall back to traditional behavior when JavaScript isn't available, such as during tests. For example, one test submits a valid vote to an AJAX-enabled action via a faux web browser and then confirms that all the proper database entries were made -- and we also have another battery of tests that cast all sorts of invalid votes and make sure that none of them make it into the database. Being able to validate the logic invoked by the AJAX actions by applying these approaches has made development much easier and less risky.