# How to Customize the Default media/fbminify Directory in OpenMage CSS/JS Minify

> Learn how to customize the default media/fbminify directory in OpenMage CSS JS Minify. Override the MINIFIED_FILES_FOLDER constant in your custom module for flexible file placement.

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

---

**Customize the minified files directory by rewriting the `Fballiano_CssjsMinify_Model_Observer` class and overriding the `MINIFIED_FILES_FOLDER` constant in your custom module.**

The fballiano/openmage-cssjs-minify extension stores generated minified JavaScript and CSS files in a hard-coded subdirectory of the Magento media folder. By default, this location is `media/fbminify`, defined as a class constant in the observer model. To use a different directory for these optimized assets, you must create a Magento 1 module that rewrites the observer and supplies a new folder name.

## Understanding the Hard-Coded Directory

The extension defines the output location 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 line 10:

```php
public const MINIFIED_FILES_FOLDER = 'fbminify';

```

When the observer processes assets, it constructs the full path by appending this constant to the media base directory:

```php
$mediaDir = Mage::getBaseDir('media');
$minifiedDir = "{$mediaDir}/" . self::MINIFIED_FILES_FOLDER . '/';

```

Because this value is hard-coded as a constant, you cannot change it via configuration files alone. The extension builds both the filesystem path and the resulting URL using this single constant, ensuring consistency between where files are stored and how they are served.

## Rewriting the Observer Class

To customize the directory, create a custom module that **rewrites** the original observer class. This approach preserves the original extension files while allowing you to override specific behavior.

### 1. Create the Module Declaration

First, register your module in the Magento global configuration:

```xml
<!-- app/etc/modules/Mycompany_CssjsMinify.xml -->
<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_CssjsMinify>
            <active>true</active>
            <codePool>community</codePool>
        </Mycompany_CssjsMinify>
    </modules>
</config>

```

### 2. Configure the Class Rewrite

Declare the rewrite in your module's configuration to intercept the original observer:

```xml
<!-- app/code/community/Mycompany/CssjsMinify/etc/config.xml -->
<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_CssjsMinify>
            <version>0.1.0</version>
        </Mycompany_CssjsMinify>
    </modules>

    <global>
        <models>
            <fballiano_cssjsminify>
                <rewrite>
                    <observer>Mycompany_CssjsMinify_Model_Observer</observer>
                </rewrite>
            </fballiano_cssjsminify>
        </models>
    </global>
</config>

```

This XML configuration instructs Magento to instantiate your custom class instead of `Fballiano_CssjsMinify_Model_Observer` whenever the observer model is requested.

### 3. Implement the Custom Observer

Create the observer class that extends the original and overrides the folder constant:

```php
<?php
/**
 * Custom observer that overrides the minified files directory.
 */
class Mycompany_CssjsMinify_Model_Observer extends Fballiano_CssjsMinify_Model_Observer
{
    public const MINIFIED_FILES_FOLDER = 'custom_min';
}

```

With this override, all operations that previously referenced `fbminify` now use `custom_min`. The parent class methods automatically pick up the new constant value when building paths like `$minifiedDir` and constructing URLs for the minified assets.

## Optional: Making the Directory Configurable

For greater flexibility, you can read the directory name from Magento's configuration system instead of hard-coding it in the class. This allows administrators to change the folder via XML updates without modifying PHP files.

Add a configuration node to your module:

```xml
<!-- Inside app/code/community/Mycompany/CssjsMinify/etc/config.xml -->
<mycompany_cssjsminify>
    <minified_folder>custom_min</minified_folder>
</mycompany_cssjsminify>

```

Then modify your observer to check this configuration:

```php
<?php
class Mycompany_CssjsMinify_Model_Observer extends Fballiano_CssjsMinify_Model_Observer
{
    public static function getMinifiedFolder()
    {
        $folder = Mage::getStoreConfig('mycompany_cssjsminify/minified_folder');
        return $folder ?: parent::MINIFIED_FILES_FOLDER;
    }
}

```

Note that using this approach requires additional modifications to replace `self::MINIFIED_FILES_FOLDER` references with `self::getMinifiedFolder()` throughout the class logic, or alternatively, defining the constant dynamically if using PHP 8.2+ features, though the constant override method remains the most straightforward for Magento 1.

## Verification Steps

After deploying your custom module:

1. Clear the Magento cache by removing files from `var/cache/`:

   ```bash
   rm -rf var/cache/*
   ```

2. Load a frontend page that includes JavaScript or CSS assets to trigger the minification process.

3. Check your media directory for the new folder:

   ```bash
   ls media/custom_min/
   ```

   You should see minified files with hashed filenames like [`a1b2c3d4-1703123456.js`](https://github.com/fballiano/openmage-cssjs-minify/blob/main/a1b2c3d4-1703123456.js).

4. View the page source and confirm that asset URLs reference the new directory (e.g., `media/custom_min/` instead of `media/fbminify/`).

If the files appear in your custom directory and the site loads without 404 errors for CSS/JS resources, the customization is working correctly.

## Summary

- The default `media/fbminify` path is defined by the `MINIFIED_FILES_FOLDER` constant 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).
- To change this directory, rewrite the observer class in a custom module and override the constant with your preferred folder name.
- This method ensures the original extension remains unmodified, preventing merge conflicts during future updates.
- Optionally, implement a configuration node to allow XML-based directory changes without code modifications.

## Frequently Asked Questions

### Can I change the minified files directory without creating a custom module?

No, the directory is hard-coded as a PHP class constant in the source code. According to the fballiano/openmage-cssjs-minify implementation, there is no system configuration field or XML setting that controls this path. Creating a module rewrite is the standard Magento 1 method for overriding class constants in third-party extensions.

### Will changing the folder affect existing minified files?

Yes, existing files in `media/fbminify/` will not be automatically moved or copied to the new location. When you change the directory, the extension generates new minified files in the customized location on the next page load. You should manually migrate any existing files or allow the system to regenerate them, and update any hard-coded references in custom themes or external caching systems.

### How do I verify that my custom directory is being used?

Check the filesystem for the presence of minified files in your new directory (e.g., `media/custom_min/`) and inspect the HTML source of your pages. The `<script>` and `<link>` tags should reference URLs containing your custom folder name instead of `fbminify`. Additionally, the `var/log/system.log` may contain references to the minification process if logging is enabled.

### Is it safe to update the extension after applying this rewrite?

Yes, because you are using Magento's class rewrite system rather than modifying the original extension files. Updates to the fballiano/openmage-cssjs-minify repository will replace the core files but leave your custom module intact. However, review the changelog for any modifications to the `MINIFIED_FILES_FOLDER` constant or the observer logic that might require adjustments to your override class.