Rails Speed Tip: link_tag Caching

Have you ever tried concatenating your JavaScript and CSS files for performance improvements? The idea is that latency is a bigger issue than file size when loading web pages, so stuffing all your JavaScript into a monolithic file for deployment should improve performance.

I wrote a rake task to do this for some of my applications (such as tiktrac). This is slightly more cumbersome than a feature I spied in the ActionPack changelog:

Read More →

Dashboard Widgets are Great with Prototype

One of my commercial projects this year was to build an online ticket sales system for a large bar and venue company in London. The run up to Christmas was the big live test of the system, so they needed statistics on ticket sales.

Just for fun, I decided to make a Dashboard widget that used curl to fetch the current data from a script on their server. But you know what made this task 100% less painful? My old friend Prototype.js.

Read More →

Server-Sent Events in Opera

Apparently, Opera 9 supports Server–Sent Events which you can read about in the WHATWG Web Applications 1.0 specification. Their demo application is a little chat program, which is a very obvious example of the technology.

There’s many times when I’ve wanted to add this to my applications: in Bugtagger I have to ask the service if a new message from a customer has been posted to a bug, every n seconds. It would be far more efficient for the serve to send a message using this technology.

Read More →

Easy Zip Compression in Ruby

I needed a quick way of exporting data as zlib from a controller in Rails, so I came up with this:

def export
  send_data compress_string(Document.find_all.to_xml), :filename => 'backup.xml.gz'
end

def compress_string(data)
  gz = Zlib::GzipWriter.new(StringIO.new(''))
  gz.write data
  gz.close.string
rescue
  gz.close
  raise
end

Another way would be to use tempfiles with Tempfile — I wanted to benchmark and profile using files compared to StringIO, but that’ll be an exercise for another day.

Read More →

Rails Time Saving Tips

I’ve created quite a few Rails projects over the last year, some commercial projects, and others are applications released under Helicoid. Here’s a few things I’ve found save time and help make projects as maintainable as possible.

Named routes

You can refer to routes in your forms and links like this: document_edit_url(:id => document.id). Isn’t that much nicer than other means? It can often make code easier to understand quickly, thus helping maintainability.

Read More →