Use cookie-free domains for components in ruby on rails application.

Use cookie-free domains for components in ruby on rails application is important to speed up your website. If you deliver assets (image, stylesheet, and javascript) from the same domain, the server will pass cookies for each asset request, which is not necessary and waste your bandwidth and according to one of the Yahoo’s best practices use cookie-free domains for components for speeding up your web site.

We can do the same thing in Ruby on Rails by defining a different domain for application and assets, that make your assets load faster.

Create a subdomain for your application and use that subdomain to deliver assets for the application. So once subdomain created and propagated paste this in your production.rb

  config.action_controller.asset_host =""

Then create an asset host like this

For Nginx:

  server {
      listen 80;
      root /home/deployer/my_rails_app/production/current/public;

For Apache

  DocumentRoot /home/deployer/my_rails_app/production/current/public

Now just restart your server and again deploy your application. You will see all the assets are loaded from without cookies. Check GTMetrics ratings for more optimisations.