Thursday, August 18, 2011

Stategies to Reduce Bandwidth When Hosting Rails



There are four resources in combination with every Rails site: CPU, memory, disc drive space, and network bandwidth. Rails hosting providers sets limits and structure accounts depending on how lots of these resources your internet site consumes. Much is discussed performance optimization get rid of CPU and memory usage. I would like to write a little bit regarding how to optimize the fourth resource, network bandwidth.

1. Compress Your Images

When adding images for the Rails site, this can be a wise decision to jog them by using a image compressor. These compressors will attempt unpick any data within the image while trying will not customize the quality or use the way it's. You can imagine it treatment of invisible data within the image. As a result your images smaller that may lower the bandwidth you have to send the theifs to the customers.

2. Minify your CSS and JavaScript

Minify is mostly a approach to compress your CSS and JavaScript by removing unnecessary characters through the file. This consists of removing empty lines, comments, and consolidating your code that should be smaller. When JavaScript is minified, it may really slow up the size nonetheless you have to do a screening test belonging to the minified JavaScript to make certain that still runs correctly. Sometimes the minification process will remove excessive code, breaking it. Once these files are minified, they should be smaller in dimensions which is able to mean you'll use less bandwidth to transmit them how to your website visitors.

3. Enable gzip On the Web Server

gzip is actually a standard text compression algorithm. It really is complex to clarify the truth dissected even so the eating habits study it are that any file that may be gzipped are going to be smaller larger. When gzip is enabled inside internet browser, all the content sent with the server will undoubtedly be compressed automatically. Modern browsers have the ability to detect gzipped data and automatically decompress it in your visitor to find out. The wonderful thing about gzip is it are doing fine with Rails for your dynamic pages too, helping you save acquiring bandwidth. The negative effects to gzip is it will have a lot more CPU on the server per file that gets compressed.

4. Convert Icons To Sprites

On your Rails application, prehaps you are using several small images as icons. While these images are tiny and don't utilize up much bandwidth alone, should you have a variety of them they'll likely will affect your bandwidth. There's an easy method to convert loads of small images right into a single one, called sprites. This implies these potential customers only will have got to download one image rather than multiple ones, saving several requests.

5. Host User Uploads On Another System

User uploaded files normally takes up a large part of your bandwidth, both should the user uploads the file and while you permit them download the file later. Particularly if allow large files like movies or audio, this will likely quickly exceed your bandwidth allotments. Very best way to fix this is often to mail your user uploaded content even to another system, similar to Amazon S3. You must pay to save files there and then any bandwidth used, however it can help you save bandwidth for your main servers. You too can have users upload files straight to S3, helping you save the upload bandwidth also.

These are a couple of the easy techniques that you can lower your bandwidth over a Ruby on Rails website. With one, try to be in a position to reduce your bandwidth usage a minimum of by 50 percent or even more.

.