Skip to content

Commit

Permalink
updating readme with various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sbecker committed Dec 23, 2006
1 parent 82c01e0 commit 06c169a
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions README
Expand Up @@ -5,15 +5,15 @@ JavaScript and CSS Asset Compression for Production Rails Apps
== Description

When it comes time to deploy your new web application, instead of
sending down a dozen javascript and css files full of formatting
sending down a dozen JavaScript and CSS files full of formatting
and comments, this Rails plugin makes it simple to merge and
compress JavaScript and CSS down into one or more files, increasing
speed and saving bandwidth.

When in development, it allows you to use your original versions
and retain formatting and comments for readability and debugging.

Because not all browsers will dependably cache javascript and css
Because not all browsers will dependably cache JavaScript and CSS
files with query string parameters, AssetPackager writes a timestamp
or subversion revision stamp (if available) into the merged file names.
Therefore files are correctly cached by the browser AND your users
Expand All @@ -28,16 +28,16 @@ I
== Credit

This Rails Plugin was inspired by Cal Henderson's article
"Serving Javascript Fast" on Vitamin:
"Serving JavaScript Fast" on Vitamin:
http://www.thinkvitamin.com/features/webapps/serving-javascript-fast

It also uses the Ruby Javascript Minifier created by
It also uses the Ruby JavaScript Minifier created by
Douglas Crockford.
http://www.crockford.com/javascript/jsmin.html

== Key Features

* Merges and compresses javascript and css when running in production.
* Merges and compresses JavaScript and CSS when running in production.
* Uses uncompressed originals when running in development.
* Handles caching correctly. (No querystring parameters - filename timestamps)
* Versions each package individually. Updates to files in one won't re-trigger downloading the others.
Expand All @@ -46,21 +46,26 @@ http://www.crockford.com/javascript/jsmin.html

== Components

* Rake Task for merging and compressing javascript and css files.
* Helper functions for including these javascript and css files in your RHTML.
* YAML configuration file for mapping javascript and css files to merged versions.
* Rake Task for auto-generating the YAML file from your existing javascript files.
* Rake Task for merging and compressing JavaScript and CSS files.
* Helper functions for including these JavaScript and CSS files in your views.
* YAML configuration file for mapping JavaScript and CSS files to merged versions.
* Rake Task for auto-generating the YAML file from your existing JavaScript files.

== How to Use:

1. Download and install the plugin:
./script/plugin install http://sbecker.net/shared/plugins/asset_packager

2. Run the rake task "asset:packager:create_yml" to generate the /config/asset_packages.yml file the first time. You
will need to reorder files under 'base' so dependencies are loaded in correct order. Feel free
to rename or create new file packages.
2. Run the rake task "asset:packager:create_yml" to generate the /config/asset_packages.yml
file the first time. You will need to reorder files under 'base' so dependencies are loaded
in correct order. Feel free to rename or create new file packages.

Example from a fresh rails app after running the rake task. (Stylesheets is blank because a default rails app has no stylesheets yet.):
IMPORTANT: JavaScript files can break once compressed if each statement doesn't end with a semi-colon.
The minifier puts multiple statements on one line, so if the semi-colon is missing, the statement may no
longer makes sense and cause a syntax error.

Example from a fresh rails app after running the rake task. (Stylesheets is blank because a
default rails app has no stylesheets yet.):

---
javascripts:
Expand Down Expand Up @@ -94,13 +99,17 @@ stylesheets:
- foo
- bar

3. Run the rake task "asset:packager:build_all" to generate the compressed, merged versions for each package. Whenever you rearrange the yaml file, you'll need to run this task again. Merging and compressing is expensive, so this is something we want to do once, not every time your app starts. Thats why its a rake task.
3. Run the rake task "asset:packager:build_all" to generate the compressed, merged versions
for each package. Whenever you rearrange the yaml file, you'll need to run this task again.
Merging and compressing is expensive, so this is something we want to do once, not every time
your app starts. Thats why its a rake task.

4. Use the helper functions whenever including these files in your application. See below for examples.

5. Potential warning: css compressor function currently removes css comments. This might blow away some css hackery. To disable comment removal, comment out /lib/synthesis/asset_package.rb line 167.
5. Potential warning: css compressor function currently removes CSS comments. This might blow
away some CSS hackery. To disable comment removal, comment out /lib/synthesis/asset_package.rb line 176.

== Javascript Examples
== JavaScript Examples

Example call:
<%= javascript_include_merged 'prototype', 'effects', 'controls', 'dragdrop', 'application', 'foo', 'bar' %>
Expand Down

0 comments on commit 06c169a

Please sign in to comment.