Symfony Compress Plugin

A symfony plugin to compress (combine and minify) javascript and stylesheet assets.

This plugin is for symfony version 1.4 or above (however should also work with version 1.0 and above, although untested).

Download

bedicanCompressPlugin 1.1bedicanCompressPlugin-1.1.zipDownload

Configuration

The following shows the plugin app.yml configuration file with default values. You should override the relevant options within your applications app.yml configuration file.

all:
  compress:
    # Enable plugin, value can be,
    #  false   - Use symfony behaviour.
    #  true    - Combine and minify.
    #  combine - Combine but do not minify.
    enabled: false
    # Use client cache buster. The file modification time of the project root
    # directory is appended to the generated url.
    client_cachebuster: true
    # The file list to key translation method, value can be,
    #  simple    - The key is the urlencoded list itself.
    #  memcached - The key is a hash with the list stored with memcached (recommended).
    key_translation: memcached
    # The maximum number of files per combined request.
    max_files_combined: 10
    # The maximum number of files.
    max_files: 100
    # Sets the Expires header, if ommited values within cache.yml is used.
    expires: 86400

    css:
      # Override for app_compress_enabled for css files.
      # enabled: true
      # Processor class.
      class: CssMinifier
      # Which files to exclude, wildcards may be used,
      # *  matching any character not including forward slash.
      # ** matching any character including forward slash.
      excludes: [ ]

    js:
      # Override for app_compress_enabled for js files.
      # enabled: true
      # Processor class.
      class: JsMinifier
      # Which files to exclude, wildcards may be used,
      # *  matching any character not including forward slash.
      # ** matching any character including forward slash.
      excludes: [ ]

Installing

Unpack the plugin to the plugins directory, enable it and change your applications settings.yml configuration file to enable the compress module and add the Compress helper to the list of standard helpers.

all:
  .settings:
    enabled_modules: [ compress, ... ]
    standard_helpers: [ Compress, ... ]

The following should be added to the applications layout to include the combined javascript and stylesheet assets.

<head>
  ...
  <?php include_combined_stylesheets() ?>
  <?php include_combined_javascripts() ?>
</head>

License

© Copyright 2010, 2012 Bedican Solutions

Redistribution and use of this software is permitted providing the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.