There are four resources used with every Rails site: CPU, memory, hard disk space, and network bandwidth. Rails hosting providers will set limits and structure accounts based on how much of these resources your site consumes. Much has already been written about performance optimization to reduce CPU and memory usage. I'd like to write a bit about how to optimize the fourth resource, network bandwidth.
1. Image Compression
When compared to text, images are huge files. A small 1 inch square can use as much storage as an entire page of text. Since images have to be sent completely to the visitor before they appear, this means your site will be sending a lot more data as images than as text. A good optimization to do is to run all of your images through an image compressor. This tool will examine your image and try to remove all of the data it can, while making sure the image still looks the same to our eyes. You don't need to understand how they work, just that they can shrink image file sizes automatically.
2. Minify all JavaScript and Stylesheets
Minify is a way to compress your CSS and JavaScript by removing unnecessary characters from the file. This includes removing empty lines, comments, and consolidating your code to be smaller. When JavaScript is minified, it can really reduce the size but you need to do a test of the minified JavaScript to make sure that it still runs correctly. Sometimes the minification process will remove too much code, breaking it. Once these files are minified, they will be much smaller in size which will mean you will use less bandwidth to send them to your visitors.
3. gzip Your Page Responses
gzip is a standard text compression algorithm. It is complex to explain how it works but the results of it are that any file that is gzipped will be smaller in size. When gzip is enabled in the web browser, all of the content sent from the server will be compressed automatically. Modern browsers are able to detect gzipped data and automatically decompress it for your visitor to see. The great thing about gzip is that it will work with Rails on your dynamic pages too, saving you a lot of extra bandwidth. The downside to gzip is that it will consume a little more CPU on the server for every file that gets compressed.
4. Merge Small Images and Icons To Sprites
It's common to use small icons in web applications to make them more usable. Unfortunately this means that a browser has to download each icon one at a time from your server. A newer technique you can use is to combine all of the icons into a single image, called a sprite. These larger images are sent to the browser once and then "trimmed up" in the user's browser. This won't save you a lot of bandwidth when compared to other tips, but it will save you some since there is less requests sent to the server.
If you can put these tips into use with your Rails application, you should be able to reduce your bandwidth usage by 50% or more. The best thing to do is to pick one to start with and implement it this week. Then next week pick another and keep going until you are done or your bandwidth usage has dropped enough.
Author Resource:
Another option is to use a Rails host that gives you unlimited bandwidth like Host Gator Rails .