BillyBib
BillyBib

Reputation: 315

None of my Rails 5 assets are minifying in production

I have a Rails 5.0.0.1 app on Heroku and when I hit the developer console in Chrome and open up the CSS and JS files I can see that neither of them have been minified. This was first brought to my attention after completing a Google speed test.

This is what some of my setup looks like...

application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require bootstrap-sprockets
//= require trix
//= require_tree .

application.scss

//Import bootstrap-sprockets
@import "bootstrap-sprockets";


// Import cerulean variables
@import "bootswatch/flatly/variables";

// Then bootstrap itself
@import "bootstrap";
@import "font-awesome";

// Bootstrap body padding for fixed navbar
/*body { padding-top: 60px; }*/

// And finally bootswatch style itself
@import "bootswatch/flatly/bootswatch";

// Whatever application styles you have go last
@import "overrides";
@import "trip";

I'm using the following gems:

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'bootswatch-rails'
gem 'bootstrap-social-rails'
gem 'bootstrap_form'

And I have the following options set in production.rb

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

I've precompiled and cleaned the assets and I've even bumped the assets version using

Rails.application.config.assets.version = '1.1'

I even nuked hell out of my assets folder using rake assets:clobber

Really at a loss now as to why none of these assets are minifying. Any help is much appreciated.

Upvotes: 0

Views: 1533

Answers (2)

Robert Nubel
Robert Nubel

Reputation: 7522

To summarize the conclusion from my and OP's comments on the main post, the issue was not that minification isn't working, but that the minified assets weren't being used. This is because the assets at one point had been precompiled into public/assets and checked into Git; the public, unminified assets then took precedence over the minified assets when being served.

The solution, then, was to remove those artifacts from Git:

git rm -r public/assets

Checking precompiled assets into version control is generally discouraged, although it depends on your deployment system. With Heroku, there's usually no need. See Do you add public/assets in version control? for more details.

Upvotes: 1

Jacob Gillespie
Jacob Gillespie

Reputation: 4081

What's your Gemfile look like? Is there a JavaScript runner for the uglifier? therubyracer is often used, and I have been fairly happy with mini_racer and its enhanced performance.

In your Gemfile:

gem 'mini_racer'

Then run bundle install and commit.

Upvotes: 2

Related Questions