Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset pipeline not compressing javascripts into application.js

I have two questions.

  1. Am I making a wrong assumption that all my javascripts should be compressed into application.js by default in rails 3.1 even in development mode?

  2. If not, then why does my tag have all 30 of my javascripts and take forver to load?

My application.js file looks like this:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

And in the browser it is rendered as:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file. 
//
;

While all my other javascripts are rendered in full.

Thank a bunch!

like image 242
jdkealy Avatar asked Oct 17 '11 18:10

jdkealy


1 Answers

If this is a new Rails app debug mode is on by default. Debug mode tell Sprockets to write tags for each file into the HTML source. This is done to facilitate source file debugging.

If you want to have just one file in development mode go to your development.rb and set:

config.assets.debug = false

This will give you one file for each manifest.

Compression is NOT on by default for development, but if you wanted that too, then set:

config.assets.compress = true

And you will need to move the compressor options from production.rb to application.rb so they are accessible to the development environment.

I turn debug off in dev mode, but I don't use compression because of the extra time it takes to process the files.

like image 173
Richard Hulse Avatar answered Nov 13 '22 14:11

Richard Hulse