Merge JS plugin

Plugin details

Easily merge, compress, cache, and version your javascript with Ruby on Rails!

With the sudden overwhelming desire we web developers feel to write AJAX apps, JavaScript has suddenly jumped to the forefront of our work. The amount of javascript files in our applications is proliferating with no end in sight.

We feel a pang of regret each time we create a new one, knowing we just added one more HTTP request for our end-users, and thus an increase in load time.

Wouldn't it be nice to logically separate our JavaScript files into small, meaningful chunks without an extra request to the server for each one? Now you can!

When running in production, instead of sending down a dozen javascript files full of formatting and comments, this plugin allows you to merge and compress javascript down into one or more files, thus saving download time for your users.

But when in development, it would be nice to use the formatted, commented and logically separated versions for ease of development and debugging.

This plugin makes it easy to do both.

Because not all browsers will dependably cache javascript files with query string parameters, we write a datetime stamp into the merged file names. Therefore files are correctly cached by the browser AND your users always get the latest version when you re-deploy!

Websitehttp://synthesis.sbecker.net/pages/asset_packager Repositoryhttp://sbecker.net/shared/plugins/merge_js/ Author Scott Becker Tags CSS, Javascript LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://sbecker.net/shared/plugins/merge_js/

=== Components

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

1. Run the rake task "generate_js_yml" to generate the /config/js.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 collections.

Example with multiple merged files:

  --- 
  source_map: 
  - rails_base: 
    - prototype
    - effects
    - controls
    - dragdrop
  - app_lib: 
    - application
    - foo
    - bar
  current_version: "20060603144038"



2. Run the rake task "merge_js" to generate the merged javascript files.

3. Use the helper function whenever including these files in your application.

Example:

<%= javascript_include_merged 'prototype', 'effects', 'controls', 'dragdrop', 'application' %>



Now supports symbols and :defaults as well:

<%= javascript_include_merged :defaults %>
<%= javascript_include_merged :foo, :bar %>

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (2 older versions) | Last edited by: Guest, 7 months ago