# What Criteria OpenMage CSS/JS Minify Uses to Identify Already Minified Files

> Discover how OpenMage CSS/JS Minify identifies minified files using filename patterns and the isAlreadyMinified method to avoid double processing and improve performance.

- Repository: [Fabrizio Balliano/openmage-cssjs-minify](https://github.com/fballiano/openmage-cssjs-minify)
- Tags: internals
- Published: 2026-03-01

---

**OpenMage CSS/JS Minify identifies already-minified files by checking if the filename matches the regular expression `[._-](min|pack)\.` via the `Fballiano_CssjsMinify_Model_Observer::isAlreadyMinified()` method, skipping minification to prevent double-processing.**

The `fballiano/openmage-cssjs-minify` extension optimizes Magento and OpenMage storefronts by compressing CSS and JavaScript assets on the fly. To avoid corrupting pre-compressed vendor libraries, the module applies specific **filename-based criteria** to determine whether an asset has already been minified before processing.

## The Filename-Based Detection Criteria

The detection logic centers on a single regular expression that examines the file path for specific naming markers. According to the source code in [`app/code/community/Fballiano/CssjsMinify/Model/Observer.php`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/app/code/community/Fballiano/CssjsMinify/Model/Observer.php) at lines 12-15, this criteria distinguishes between raw and pre-minified assets.

### The Regex Pattern

The `isAlreadyMinified()` method uses the following pattern to evaluate filenames:

```php
/[._-](min|pack)\./

```

This regular expression searches for a dot (`.`), underscore (`_`), or hyphen (`-`) immediately followed by either `min` or `pack`, ending with a literal dot before the file extension. When the filename contains sequences like `.min.`, `-pack.`, or `_pack.`, the method returns `true`.

### The isAlreadyMinified() Method

The static method `Fballiano_CssjsMinify_Model_Observer::isAlreadyMinified()` encapsulates the regex check. This method is called during the `http_response_send_before` event to screen each asset before minification begins.

## Recognized File Naming Conventions

Files matching these criteria are treated as already minified and bypass the minification engine:

- [`script.min.js`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/script.min.js) — dot separator with "min"
- [`style.min.css`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/style.min.css) — dot separator with "min"
- [`vendor-pack.js`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/vendor-pack.js) — hyphen separator with "pack"
- [`theme_pack.css`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/theme_pack.css) — underscore separator with "pack"

Any combination of `.`, `_`, or `-` before `min` or `pack` satisfies the detection regex used by the observer.

## Workflow Implementation

When handling the `http_response_send_before` event, the observer evaluates each asset path to determine the processing strategy. As implemented in `fballiano/openmage-cssjs-minify`, the logic branches based on the detection result:

```php
if (self::isAlreadyMinified($path)) {
    // Just copy the original file to the cache folder
    @copy($baseDir . $path, $minifiedDir . $hash);
} else {
    // Run the appropriate minifier (JS or CSS)
    $minifier = new \MatthiasMullie\Minify\JS($baseDir . $path);
    $minifier->minify($minifiedDir . $hash);
}

```

When `isAlreadyMinified()` returns `true`, the file is copied unchanged to the minified cache directory. Otherwise, the asset is processed by the **Matthias Mullie** minification library to generate the compressed version.

## Testing the Detection Criteria Programmatically

Developers can verify the detection logic directly using the observer model to test specific file paths:

```php
$observer = new Fballiano_CssjsMinify_Model_Observer();

$files = [
    '/js/app.min.js',
    '/js/lib.js',
    '/css/theme-pack.css',
    '/css/style.css'
];

foreach ($files as $file) {
    $already = $observer::isAlreadyMinified($file)
        ? 'already minified'
        : 'needs minification';
    echo "$file → $already\n";
}

```

**Output:**

```

/js/app.min.js → already minified
/js/lib.js → needs minification
/css/theme-pack.css → already minified
/css/style.css → needs minification

```

## Summary

- **Regex criteria**: The extension uses `/[._-](min|pack)\./` to test filenames for `min` or `pack` markers preceded by `.`, `_`, or `-`.
- **Source location**: Detection logic resides in `Fballiano_CssjsMinify_Model_Observer::isAlreadyMinified()` within [`app/code/community/Fballiano/CssjsMinify/Model/Observer.php`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/app/code/community/Fballiano/CssjsMinify/Model/Observer.php) (lines 12-15).
- **Processing bypass**: Matched files are copied unchanged to the cache directory; unmatched files are processed by the Matthias Mullie minifier.
- **Naming conventions**: Standard patterns like `.min.`, `-pack.`, and `_pack.` are automatically recognized as already minified.

## Frequently Asked Questions

### What regex pattern does OpenMage CSS/JS Minify use to detect minified files?

The extension uses the pattern `/[._-](min|pack)\./` which looks for a dot, underscore, or hyphen followed by "min" or "pack" immediately before the file extension dot. This regex is hardcoded in the `isAlreadyMinified()` method and applies to both JavaScript and CSS assets.

### Where is the detection logic located in the source code?

The detection logic is implemented in the `isAlreadyMinified()` method of the `Fballiano_CssjsMinify_Model_Observer` class, found in [`app/code/community/Fballiano/CssjsMinify/Model/Observer.php`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/app/code/community/Fballiano/CssjsMinify/Model/Observer.php) at lines 12-15 according to the repository source.

### Does OpenMage CSS/JS Minify check file content or just the filename?

The module checks only the filename against the regex criteria. It does not inspect file contents, headers, or bytecode to determine minification status, relying entirely on naming conventions like `.min.` or `-pack.` to identify pre-compressed assets.

### What happens when a file is identified as already minified?

When `isAlreadyMinified()` returns `true`, the observer copies the original file directly to the minified cache directory without running it through the Matthias Mullie minification library. This preserves the existing compression and avoids potential corruption from double-minification.