3 simple tips that will make your Rails application faster, part # 1

      I know that many people have already written guides to help your web application run faster. But I will try to focus on the simplest but most effective methods that will help you significantly speed up your application without losing any functionality from Ruby on Rails.
    Tip # 1: Get your static content
    Tip # 2: Get all the redundant
    Tip # 3: Cache your entire page

    Tip # 1: Get your static content
      It often happens that one web application loads several javascripts and css styles at once. This significantly slows down the page loading as the web browser opens a new connection each time for a new file.
    The solution is to reduce the number of external resources of your page by combining them all into one file. The AssetPackager plugin will help us in this. Set

      :   Example config / asset_packages.yml:   And run rake task:   Next we write for javascript   For styles we write:   As a result, we get our old code for development mode, for example:   And in production mode it will be:   Now, to do the load more less we transfer all our static files to another host (why here ) In rails it is very simple to do, just add the following line to config / environments / production.rb: Now all image_tag, javascript_include_tag, etc. will point to this host. UPD
    script/plugin install git://github.com/sbecker/asset_packager.git


    ---
    javascripts:
    - base:
      - prototype
      - effects
      - controls
      - dragdrop
      - application
    - secondary:
      - foo
      - bar
    stylesheets:
    - base:
      - screen
      - header
    - secondary:
      - foo
      - bar


    rake asset:packager:build_all


    <%= javascript_include_merged :base %>
    или
    <%= javascript_include_merged 'prototype', 'effects', 'controls', 'dragdrop', 'application' %>


    <%= stylesheet_link_merged :base %>
    или
    <%= stylesheet_link_merged 'screen', 'header' %>

















    config.action_controller.asset_host = "http://assets.example.ru"



    : Instead of the plugin, you can use <% = javascript_include_tag: all,: cache => true%>, more details here . Thanks grossu

    Also popular now: