Once installed there is little you need to do. Jazz takes any files in the public/javascripts/jasmin folder runs jsmin over them and the sets them back in the public/javascripts folder. Much of the code was borrowed from the SASS part of HAML. You will need the jsmin gem:
gem install jsmin script/plugin install git:https://github.com/adamelliot/jasmin.git
If you want to use Jasmin all the time (by default it’s only on in production to make sure JS debugging isn’t a nightmere) add an initializer:
Jasmin.options[:always_minify] = true
Any files that you don’t want minified just leave in the javascripts folder and they won’t be touched. Make sure not to create a file of the same name in the jasmin folder, otherwise it will be overwritten.
As Jasmin is simple and doesn’t require much modifying, but there are a couple options you can tweak (many of these were stolen from the SASS docs):
:always_minify
-
Causes to be minified always. Otherwise it’s only minified in production.
:never_minify
-
Turns off minification under all environments.
:never_update
-
Whether the JS files should never be updated, even if the template file changes. It always defaults to false.
:always_update
-
Whether the JS files should be updated every time a controller is accessed, as opposed to only when the template has been modified. Defaults to false.
:always_check
-
Whether a JS files should be checked for updates every time a controller is accessed, as opposed to only when the Rails server starts. If a JS file has been updated, it will be minified and will overwrite the corresponding JS file. Defaults to false in production mode, true otherwise.
:template_location
-
The directory where javascripts should be read from. Defaults to RAILS_ROOT + “/public/javascripts/jasmin”.
:js_location
-
The directory where JS output should be written to. Defaults to RAILS_ROOT + “/public/javascripts”
Caution (taken from: www.crockford.com/javascript/jsmin.html)¶ ↑
Be sure to retain your original source file. JSMin is a one-way trip: Once done, it cannot be undone.
Do not put raw control characters inside a quoted string. That is an extremely bad practice. Use xhh notation instead. JSMin will replace control characters with spaces or linefeeds.
Use parens with confusing sequences of + or -. For example, minification changes
a + ++b
into
a+++b
which is interpreted as
a++ + b
which is wrong. You can avoid this by using parens:
a + (++b)
JSLint checks for all of these problems. It is suggested that JSLint be used before using JSMin.
Thanks to Hampton Catlin for HAML & SASS, made making Jasmin a piece of cake! Check them out at: