PHPackages                             johndwells/craft.minimee - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. johndwells/craft.minimee

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

johndwells/craft.minimee
========================

A Craft CMS port of the popular Minimee add-on for ExpressionEngine.

v0.9.9(8y ago)664.5k10[10 issues](https://github.com/johndwells/craft.minimee/issues)[1 PRs](https://github.com/johndwells/craft.minimee/pulls)PHP

Since Apr 20Pushed 8y ago6 watchersCompare

[ Source](https://github.com/johndwells/craft.minimee)[ Packagist](https://packagist.org/packages/johndwells/craft.minimee)[ RSS](/packages/johndwells-craftminimee/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (1)Versions (4)Used By (0)

Minimee for Craft - v0.9.9
==========================

[](#minimee-for-craft---v099)

A [Craft CMS](http://buildwithcraft.com) port of the popular [Minimee](https://github.com/johndwells/Minimee) add-on for ExpressionEngine.

---

Minimize, combine &amp; cache your CSS and JS files. Because size (still) DOES matter.

- [On github](https://github.com/johndwells/craft.minimee)
- [Support](https://github.com/johndwells/craft.minimee/issues)

---

Features
--------

[](#features)

- Config settings will parse [Environment Variables](http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables)
- Use as a [Twig Filter](http://twig.sensiolabs.org/doc/tags/filter.html) or [Craft Variable](http://buildwithcraft.com/docs/plugins/variables)
- Can save caches either above or below webroot
- Enable/disable minification of CSS &amp; JS
- Enable/disable combination of CSS &amp; JS
- When in `devMode`, Minimee will throw `Exception`s if unable to run successfully
- When in `devMode`, will automatically attempt to clean up what it can determine are expired caches
- Override CP Settings via filesystem config (requires Craft 1.4), or at runtime
- Clear Minimee's cache from CP (Settings &gt; Tools &gt; Clear Caches)
- Ability to return contents of the cache to template

*Looking to minify your HTML, or minify inline CSS/JS? You should check out .*

---

Installation
------------

[](#installation)

1. Download latest release from [github](https://github.com/johndwells/craft.minimee/releases)
2. Copy `minimee` into your `app/plugins` directory
3. Log into Craft and go to `Settings > Plugins`
4. Click `install` for Minimee
5. Visit Minimee plugin settings and optionally configure (see below)

### Install via Composer

[](#install-via-composer)

Minimee can now be installed via [composer](https://getcomposer.org/), and is also registered on [Packagist](https://packagist.org/packages/johndwells/craft.minimee).

Note that due to the current folder structure (where the actual plugin files are not at the package root, but inside the folder `minimee`) you will need to make some adjustments to your own composer file. Composer has a `post-install-cmd` feature which is run immediately after the `composer install` command, allowing you to run additional tasks. An example of your composer file may be:

```
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/johndwells/craft.minimee.git"
    },
  ],
  "require": {
    "johndwells/craft.minimee": "v0.9.8"
  },
  "scripts": {
    "post-install-cmd": [
      "/bin/bash -c 'pushd craft/plugins && test -d minimee/minimee && mv minimee/minimee/* minimee && popd'"
    ]
  }
}

```

*Big thanks to [@jackmcpickle](https://github.com/jackmcpickle) for the pull request and subsequent assistance in documentation.*

---

Settings
--------

[](#settings)

Out of the box and when first installed, Minimee will be automatically enabled and set to combine &amp; minify both your CSS and JS assets. It will use default settings to get you up and running immediately, but you can visit the `Settings` page of the plugin to configure to suit your environment.

[![settings](minimee/resources/img/settings.png)](minimee/resources/img/settings.png)

> Note that all string settings will parse Craft's [Environment Variables](http://buildwithcraft.com/docs/config-settings#environmentVariables)

##### Filesystem Path

[](#filesystem-path)

To locate your assets on your web server, Minimee takes the path to the asset (e.g. `/asset/css/normalize.css`), and appends this to `$_SERVER['DOCUMENT_ROOT']`. This tends to work for most setups, and can be left as is.

However for a multi-lingual site, where you may have many `index.php` files (and therefore differing values of `$_SERVER['DOCUMENT_ROOT']`), but one location of CSS and JS assets, you will want to specify that singlular path location. This is when using Craft's [Environment Variables](http://buildwithcraft.com/docs/config-settings#environmentVariables) might particularly come in handy.

##### Base URL

[](#base-url)

When operating upon your CSS, Minimee needs to rewrite the paths to images &amp; fonts, so that the cached file can still successfully link to those images &amp; fonts, no matter where it may be saved. By default, the URL of your site is used, as defined in **Settings &gt; General**.

Similar to the `Filesystem Path`, this may need to be overriden in certain circumstances. In fact it's probably safe to say that if you need to override the Filesystem Path, you will want to also override the Base URL accordingly.

##### Cache Path &amp; URL

[](#cache-path--url)

By default, Minimee stores cached assets in Craft's `craft/storage` folder, which likely sits above webroot. The cache is then delivered by Craft itself, via a special "resource" url, e.g. `http://domain.com/resources/minimee/filename.timestamp.ext`.

Alternatively, you can specify a cache path &amp; URL which sits *below* webroot, so that the cached assets are delivered directly by your server. This is the recommended setup for optimal performance gains.

##### Return Templates &amp; Type

[](#return-templates--type)

By default, Minimee returns the URL to the combined &amp; minified asset. Also by default, if that asset is a CSS file, it is wrapped in a default template (``), where the URL replaces `"%s%` using PHP's [sprintf()](http://php.net/manual/en/function.sprintf.php) function. If that asset is a JS file, the default template is ``.

You may override this behaviour to do things such as load Javascript asynchronously, or embed CSS inline. These settings are especially useful being used at runtime (see below).

##### CSS Prepend URL

[](#css-prepend-url)

When Minimee processes CSS files, it will by default alter any *relative* @import and image URIs (e.g. `url("../img/arrow.svg")`) to be a fully-qualified URL, using the asset's URL as the basis. This ensures that the links will remain intact regardless of where your might save the cached files.

You can opt to turn this feature off; additionally you can override the prepended URL to something custom. This is particularly useful if you would like to upload your static assets to a CDN, or link to assets through a cookie-less domain.

### Runtime Settings

[](#runtime-settings)

In addition to specifying configuration settings via the CP, you can also pass an array of settings when calling any of Minimee's tags below. For example, you can create this simple [Twig hash](http://twig.sensiolabs.org/doc/templates.html#literals), and then pass it as a parameter to either of Minimee's template tags:

```
{#
	Tip: In your template you can access Craft's environment Variables like so:
	craft.config.environmentVariables['variableName']
#}

{% set minimeeSettings = {
	'enabled' : true,
	'combineCssEnabled' : true,
	'combineJsEnabled' : true,
	'minifyCssEnabled' : true,
	'minifyJsEnabled' : true,
	'filesystemPath' : '/var/www/public/',
	'baseUrl' : 'http://craft.dev/',
	'cachePath' : '/var/www/public/cache/',
	'cacheUrl' : 'http://craft.dev/cache/',
	'cssReturnTemplate' : '',
	'jsReturnTemplate' : '',
	'returnType' : 'url',
	'cssPrependUrlEnabled' : true,
	'cssPrependUrl' : ''
} %}

```

### Filesystem Config Settings

[](#filesystem-config-settings)

As of Craft 2.0, Minimee supports the ability to override the CP Settings with filesystem configs. Note that this **does NOT** reduce any processing/DB overheads, but it may suit how you prefer to configure Minimee across multiple environments.

To use this feature, begin by copying the contents of the `minimee/config.php` file into a new file named `minimee.php`, and move it to your `craft/config` folder. Then uncomment and set as few or as many settings as you wish.

For more on how multi-environment configs work in Craft, see .

### The Settings "Cascade"

[](#the-settings-cascade)

Given all of the ways to configure Minimee, keep in mind the cascade or inheritance of these methods:

- CP settings are defaults
- Filesystem settings override CP settings
- Runtime settings override Filesystem settings

*When overriding via any method, you only need to specify those setting values which need to be different.*

---

Debugging
---------

[](#debugging)

When your site is running in [devMode](http://buildwithcraft.com/docs/config-settings#devMode), Minimee will throw an `Exception` containing any messages which indicate where an error may have occurred.

Also while in devMode, Minimee will continually try to clean your cache folder of what it can safely determine are expired caches.

---

Usage
-----

[](#usage)

There are currently two ways you can use Minimee:

1. Template Variable
2. Twig Filter

*Both methods can be passed an optional parameter of runtime settings. Refer to the section above on how to define these.*

### 1. Template Variable

[](#1-template-variable)

Minimee's template variable is attached to Craft's global variable `{{ craft }}`, and accessed via `{{ craft.minimee.css() }}` and `{{ craft.minimee.js() }}`. An array of asset paths is passed to each variable, with a second optional parameter containing an array of settings.

##### CSS:

[](#css)

```
{{ craft.minimee.css([
		'/assets/css/normalize.css',
		'/assets/css/app.css'
	])
}}

{# Optionally pass settings as 2nd parameter #}
{{ craft.minimee.css([
		'/assets/css/normalize.css',
		'/assets/css/app.css'
	], minimeeSettings)
}}

```

##### JS:

[](#js)

```
{{ craft.minimee.js([
		'/assets/js/jquery.js',
		'/assets/js/app.js'
	])
}}

{# Optionally pass settings as 2nd parameter #}
{{ craft.minimee.js([
		'/assets/js/jquery.js',
		'/assets/js/app.js'
	], minimeeSettings)
}}

```

### 2. Twig Filter

[](#2-twig-filter)

Minimee can also be used as a [filter](http://twig.sensiolabs.org/doc/tags/filter.html), providing the ability to parse and process complete HTML tags, similar to how Minimee operates as an EE plugin.

Minimee can detect which type of asset to process; you may optionally pass an array of settings to any filter.

#### CSS:

[](#css-1)

```
{% filter minimee %}

{% endfilter %}

{# Optionally pass settings as parameter #}
{% filter minimee(minimeeSettings) %}

{% endfilter %}

```

#### JS:

[](#js-1)

```
{% filter minimee %}

{% endfilter %}

{# Optionally pass settings as parameter #}
{% filter minimee(minimeeSettings) %}

{% endfilter %}

```

#### `{{ getHeadHtml }}` &amp; `{{ getFootHtml }}`:

[](#-getheadhtml----getfoothtml-)

The `filter` will also work in conjunction with Craft's [getFootHtml](http://buildwithcraft.com/docs/templating/functions#getFootHtml) and [getHeadHtml](http://buildwithcraft.com/docs/templating/functions#getHeadHtml) tags.

```
{% includeCssFile "/assets/css/normalize.css" %}
{% includeCssFile "/assets/css/app.css" %}
{{ getHeadHtml() | minimee }}

{% includeJsFile "/assets/js/jquery.js" %}
{% includeJsFile "/assets/js/app.js" %}
{{ getFootHtml() | minimee }}

{# Optionally pass settings as parameter #}
{% set minimeeSettings = {
	'enabled' : craft.config.environmentVariables['minimeeEnabled']
} %}
{{ getHeadHtml() | minimee(minimeeSettings) }}
{{ getFootHtml() | minimee(minimeeSettings) }}

```

> **Note that any inline CSS or JS passed via `{% includeJs %}`, `{% includeCss %}` and`{% includeHiResCss %}` is currently not supported.**

---

Roadmap - 1.0 release
---------------------

[](#roadmap---10-release)

- improve/refactor internal abort()
- all messages/instructions translatable
- improved logging
- validation during settings save
- ensure using best practice for method names
    - setX, getX
    - isX
    - doX
    - useX
    - protected has leading underscore?
- unit test

### Roadmap - post 1.0 release

[](#roadmap---post-10-release)

- create `*.gz` versions of cache, for serving precommpressed files automatically via [Apache](https://blog.jcoglan.com/2007/05/02/compress-javascript-and-css-without-touching-your-application-code/) or [nginx](http://wiki.nginx.org/HttpGzipStaticModule).
- publish "map" js files during development
- tie the cache hash to settings and/or last date modified of settings/config and/or minimee version?
- support [includeJs](http://buildwithcraft.com/docs/templating/tags#includeJs), [includeCss](http://buildwithcraft.com/docs/templating/tags#includeCss) and [includeHiResCss](http://buildwithcraft.com/docs/templating/tags#includeHiResCss)?
- additional hooks/events
- try to resolve URL assets to local assets

---

Unit Test All The Things
------------------------

[](#unit-test-all-the-things)

Unit Testing of this plugin is in active, sporatic, trial-and-error development. If you see anything that can improve this process, I'd welcome your thoughts. I'm fairly confident I have no idea what I'm doing, as with most things.

### Running Minimee's Tests

[](#running-minimees-tests)

To run Minimee, the following assumptions are made:

- you have PHP 5.3+ available to run from CLI
- optionally xdebug is configured for PHP if you'd like run PHPUnit's **coverage reports**.
- composer is installed globally (if installed locally, the commands below may have to be adjusted)
- you have a local copy of Craft running

With the assumptions taken care of, these steps should get you up and running:

1. Fork, clone or download the `develop` branch of Minimee
2. Symlink the `minimee` folder to Craft's `plugin` folder
3. Update line 7 of `minimee/tests/bootstrap.php` to point to your copy of Craft's boostrap.php file (e.g. `/path/to/your/craft/app/tests/bootstrap.php`)
4. In Terminal, `cd` to `minimee/tests`
5. Run `composer install --dev`
6. Run `php vendor/bin/phpunit`

*Note that for testing, it's not necessary to have Minimee installed.*

##### Note to self regarding UT

[](#note-to-self-regarding-ut)

Within MAMP Pro I have downloaded a number of PHP versions to be able to test across; I have modified the `php.ini` file of version 5.5.9 to turn on xdebug, so when wanting to run coverage reports, use this complete command: `/Applications/MAMP/bin/php/php5.5.9/bin/php vendor/bin/phpunit`

---

License
-------

[](#license)

\[[http://opensource.org/licenses/mit-license.php\](MIT](http://opensource.org/licenses/mit-license.php](MIT) License)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~468 days

Total

2

Last Release

3255d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/428d69a516c8f39bd7a93777c61766b6e62de410d3c973746fbc4803abc1c62c?d=identicon)[johndwells](/maintainers/johndwells)

---

Top Contributors

[![johndwells](https://avatars.githubusercontent.com/u/134110?v=4)](https://github.com/johndwells "johndwells (246 commits)")[![jackmcpickle](https://avatars.githubusercontent.com/u/89775?v=4)](https://github.com/jackmcpickle "jackmcpickle (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![stuart-mccoy](https://avatars.githubusercontent.com/u/424165?v=4)](https://github.com/stuart-mccoy "stuart-mccoy (2 commits)")[![bilke](https://avatars.githubusercontent.com/u/149656?v=4)](https://github.com/bilke "bilke (1 commits)")

### Embed Badge

![Health badge](/badges/johndwells-craftminimee/health.svg)

```
[![Health](https://phpackages.com/badges/johndwells-craftminimee/health.svg)](https://phpackages.com/packages/johndwells-craftminimee)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)[mautic/core

Mautic Open Source Distribution

9.8k2.6k9](/packages/mautic-core)[mediawiki/maps

Adds various mapping features to MediaWiki

78149.7k3](/packages/mediawiki-maps)[rainlab/blog-plugin

Blog plugin for October CMS

17158.6k](/packages/rainlab-blog-plugin)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

19246.3k2](/packages/civicrm-civicrm-drupal-8)[starcitizentools/citizen-skin

A beautiful, usable, responsive MediaWiki skin with in-depth extension support. Originally developed for the Star Citizen Wiki.

3355.8k](/packages/starcitizentools-citizen-skin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
