Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to render a js file with Rails and minify the output?

I'm generating some js output for each user using a template named example.js.erb. This is basically a javascript file where I have to put in the user's unique details. I'm using this inside of a widget for the user.

Is there any way to minify the js as it's being rendered? Right now the javascript is being rendered correctly, but it's in it's long form and I'd like to minify the output in order to reduce file size and increase download speed.

like image 349
markquezada Avatar asked Nov 11 '11 20:11

markquezada


1 Answers

Rails Javascript compression/minification on respond_to javascript response?

respond_to do |format|
  format.js { self.response_body = minify(render_to_string) }
end
like image 171
markquezada Avatar answered Nov 08 '22 00:11

markquezada