AJAX Interactions Need Activity Indicators

AJAX interactions from the client to the server are wonderful for user experiences. With a little JavaScript magic, form submissions, data loading, and any other interaction of the server can be done without reloading the page. One can build web applications all on one page with JavaScript frameworks like Backbone.js and Ember.js. The magic of AJAX data transmission is beautiful — until you have to wait.


Read more on AJAX Interactions Need Activity Indicators…

These Intermittent Test Failures Will Not Stand, Man

I recently spent some time cleaning up a large test suite that had fallen into a bit of disrepair. The project was a Ruby on Rails web application being tested with RSpec and Cucumber. The biggest problem was that various tests would fail intermittently. Some tests would pass consistently when run by themselves, but would frequently fail when the whole suite was run. Re-running the suite once or twice would often result in all tests passing, so the non-deterministic tests were largely ignored eventually becoming broken windows.

Read more on These Intermittent Test Failures Will Not Stand, Man…

Mobile Safari on iOS 5.1 Unexpectedly Making Cross Origin Resource Sharing Requests

I was astonished when I finally understood a problem my web application was experiencing recently: After viewing a PDF file from Mobile Safari on the iPad, the browser treated all future Ajax requests in that browser tab as Cross Origin Resource Sharing requests and subsequently sent the HTTP ‘OPTIONS’ verb, rather than the ‘GET’ verb I expected. That caused a lot of my functionality to break. It’s been quite a while since I’ve experienced a bug in my application this esoteric.

If you’ve seen this behavior in your application, you should be able to fix it by using “Content-Disposition: inline” and not “Content-Disposition: attachment”. For the long version, keep reading.

Read more on Mobile Safari on iOS 5.1 Unexpectedly Making Cross Origin Resource Sharing Requests…

Upload Files Directly to S3 with Plupload, Rails, and Paperclip

Plupload is an open source javascript upload handler that supports uploading files directly to Amazon S3. This is an alternative to uploading files to the web server, and then to S3. You will need to use the Flash or Silverlight options to upload directly to S3 because Amazon has yet to enable cross-origin uploading.

Read more on Upload Files Directly to S3 with Plupload, Rails, and Paperclip…

Chaining jQuery Ajax Calls

Starting with version 1.5, jQuery has provided Deferred Objects to make working with asynchronous functions a little easier. A canonical example of its usage might be:

$.getJSON('/dataz').then(function(objects) {
  alert('I got some json data: ' + objects.length);
});

I was recently working on some code that required making a number of sequential Ajax requests where the results of one request would determine the URL of a subsequent request. Additionally the results of later requests were building on the results of earlier requests.

Read more on Chaining jQuery Ajax Calls…

Extracting a Table from a MySQL Dump

Occasionally, I need to use the data in a single table from a full MySQL database backup dump. Ordinarily, you’d just import the database dump into MySQL and go. Unfortunately, if the dump file is several Gigabytes (even when compressed), it becomes time-consuming to SCP this file around and then load it into MySQL.

Read more on Extracting a Table from a MySQL Dump…

jQuery Ajax Memory Leak in IE8

I was surprised to find out last week that Ajax calls made with jQuery 1.4.2 leak memory in Internet Explorer 8.

The web application I am working on includes a page on which a user will spend much of their time. As the user navigates through various subsections of the page (we are using sammy.js for client side “pages”) repeated Ajax requests are made to the server for JSON data. Our exploratory tester discovered that the page was slowing down dramatically in IE8 the longer he navigated through the subsections. Further investigation revealed that the browser’s memory usage was increasing dramatically over time.

Read more on jQuery Ajax Memory Leak in IE8…

Announcers: A Layer Between the Controller and Rendering

For my last Rails project, we went to a completely Ajax interface for everything. This meant that nearly every action on a controller would result in several lines of RJS calls, along with the logic of which partial to render depending on the state of updating or creating an object.

All that logic and RJS stuff was a pain to test in a controller spec, because so much setup is needed every time you call a controller action in a test (authentication, session, etc). Any branching you have in a controller action really becomes a nuisance to test, and when the customer wants to be able to change what happens on the page when a user saves some object, rewriting those tests and the controller are even less fun.

So we came up with the idea of moving all the presentation related logic out of the controller and into helper objects we call announcers. The purpose of an announcer is to make the actual rendering calls, based on state that is passed to it by the controller.

Read more on Announcers: A Layer Between the Controller and Rendering…