How to Exclude Specific CSS or JS Files from Being Minified by the OpenMage CssjsMinify Module
Rename the files to include .min. or .pack. in their names (e.g., analytics.min.js or theme.pack.css), as the module automatically skips files matching the patterns *.min.* or *.pack.* without requiring configuration changes.
The fballiano/openmage-cssjs-minify module for OpenMage (Magento 1) automatically minifies CSS and JavaScript files to improve frontend performance. However, if you need to exclude specific CSS or JS files from being minified—perhaps because they are already optimized or break when processed—you must understand how the module's detection logic works, as it does not provide a built-in exclusion list in the admin panel.
How the Module Detects Already-Minified Files
The minification logic resides in app/code/community/Fballiano/CssjsMinify/Model/Observer.php. Before processing any asset, the module calls Fballiano_CssjsMinify_Model_Observer::isAlreadyMinified() to determine if the file has been pre-minified.
According to the source code in Observer.php (lines 12-15), this method checks the file path against a regular expression:
protected static function isAlreadyMinified($path)
{
return preg_match('/.(min|pack)\.(js|css)$/i', $path);
}
If the filename contains .min. or .pack. before the extension, the method returns true, signaling the observer to skip minification.
The Zero-Code Solution: File Naming Conventions
Because the module lacks a configuration interface for exclusions, the simplest way to exclude specific CSS or JS files from being minified is to rename them to match the detection patterns. When isAlreadyMinified() returns true, the observer copies the original file directly to the fbminify cache directory without running the minifier.
For JavaScript files referenced in your layout XML or templates:
<!-- This file will be minified -->
<script src="/js/analytics.js"></script>
<!-- This file will be excluded (copied as-is) -->
<script src="/js/analytics.min.js"></script>
For CSS files:
<!-- This file will be minified -->
<link rel="stylesheet" href="/css/theme.css" />
<!-- This file will be excluded -->
<link rel="stylesheet" href="/css/theme.pack.css" />
As implemented in Observer.php (lines 48-55 for JS and lines 78-85 for CSS), the logic branches when a match is found, preserving the original file content rather than processing it through the minification engine.
Creating a Custom Exclusion List via Module Extension
If you need to exclude files based on specific paths rather than naming conventions, you must extend the module, as the base installation does not expose a configuration node for exclusion lists.
First, add a custom configuration section to app/code/community/Fballiano/CssjsMinify/etc/config.xml under the <global> node:
<global>
<cssjsminify>
<excludes>
<exclude>/js/vendor/legacy-library.js</exclude>
<exclude>/css/admin/unsupported-theme.css</exclude>
</excludes>
</cssjsminify>
</global>
Next, modify the httpResponseSendBefore() method in Observer.php to read this configuration and skip processing for matching paths:
$excludes = Mage::getStoreConfig('cssjsminify/excludes');
if (is_array($excludes) && in_array($path, $excludes, true)) {
// Return original URL without minification
return $matches[1] . $matches[2] . $matches[3];
}
This approach allows you to exclude specific CSS or JS files from being minified based on their full path, even if they do not follow the .min. or .pack. naming convention.
Summary
- The
fballiano/openmage-cssjs-minifymodule automatically skips files matching*.min.*or*.pack.*patterns. - To exclude a file without writing code, rename it to include
.minor.packbefore the extension (e.g.,file.min.js). - The detection logic is located in
Fballiano_CssjsMinify_Model_Observer::isAlreadyMinified()inObserver.php. - For path-based exclusions, extend the module by adding configuration in
config.xmland checking it inhttpResponseSendBefore(). - Files that match the exclusion patterns are copied to the
fbminifyfolder in their original state.
Frequently Asked Questions
Does the module provide an admin configuration panel for exclusions?
No, the module does not expose a configuration option for exclusion lists in the OpenMage admin panel. You must either use the file naming convention (*.min.* or *.pack.*) or extend the module programmatically to add custom exclusion logic.
What file name patterns will prevent automatic minification?
According to the source code in Observer.php, the module checks for files ending in .min.js, .pack.js, .min.css, or .pack.css using the regex pattern /.(min|pack)\.(js|css)$/i. Any file matching these patterns is considered already minified and is excluded from processing.
Can I exclude files based on their full path rather than just the file name?
Yes, but this requires custom development. You must add an XML configuration node in config.xml to store excluded paths, then modify the httpResponseSendBefore() observer method to check the current file path against your exclusion list before processing.
Where does the module store files that are skipped due to naming patterns?
Files that match the exclusion patterns (or are successfully minified) are copied to the fbminify folder within your media directory. For skipped files, this is a verbatim copy of the original source, preserving the unminified content while allowing the module to serve it through the same pipeline.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →