Book Image

Rails 4 Application Development HOTSHOT

By : Saurabh Bhatia
Book Image

Rails 4 Application Development HOTSHOT

By: Saurabh Bhatia

Overview of this book

<p>Rails is a rapidly moving, open source, web development framework, and keeping up to speed with it is a big task. You might have already built applications using it, but there have been significant changes in the syntax and semantic of the Rails framework in the latest upgrade.</p> <p>Rails 4 Application Development Hotshot shows you how to build the most popular types of applications using Rails 4, and highlights new ways to do things. The book also closely follows lots of the best practices, gems, and popular solutions already known to the community, and tracks the changes in these. This book brings new ideas to refactor and restructure code to make it perform better in production, and enables you to write production-ready code.</p>
Table of Contents (17 chapters)
Rails 4 Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing asset caching


In our CMS there are several kinds of assets. As we build themes we will beautify them with varied JavaScript, CSS, and images. In order to keep the speed of our sites fast in the frontend, we will use asset caching in Rails.

Engage thrusters

The steps to follow will be to cache the content and speed up our site, as follows:

  1. We will first make sure we have the right asset-related gems in Gemfile:

    gem 'sass-rails', '~> 4.0.0'
    gem 'uglifier', '>= 1.3.0'
    gem 'coffee-rails', '~> 4.0.0'

    This will enable all kinds of assets and make it ready for production.

  2. We will first enable asset compression inside our production.rb file:

    config/environments/production.rb.
    config.assets.compress = true
    
  3. We will continue to edit the same file:

    config.assets.compress = true
    # Compress JavaScripts and CSS.
    config.assets.js_compressor = :uglifier
    config.assets.css_compressor = :sass
  4. We will now fix the asset folder to tmp/cache/assets:

    config/environments/production.rb
    config.assets.cache...