# How the CssjsMinify Module Supports Different Base Directories: MAHO_PUBLIC_DIR vs Mage::getBaseDir()

> Learn how the CssjsMinify module supports MAHO_PUBLIC_DIR and Mage::getBaseDir() for flexible Maho or OpenMage installations. Optimize your CSS and JS delivery now.

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

---

**The CssjsMinify module automatically detects whether it is running on a Maho installation by checking for the MAHO_PUBLIC_DIR constant, falling back to Mage::getBaseDir() for standard OpenMage or Magento 1 environments.**

The fballiano/openmage-cssjs-minify module provides automatic CSS and JavaScript minification for OpenMage and Maho installations. Understanding how it handles different base directory structures is crucial for proper asset path resolution across various Magento 1 variants.

## Runtime Base Directory Detection in the Observer

The module's core logic resides in the `httpResponseSendBefore()` method of `Fballiano_CssjsMinify_Model_Observer`. This method performs a simple runtime check to determine which base directory to use for locating original CSS and JS files.

```php
if (defined('MAHO_PUBLIC_DIR')) {
    $baseDir = MAHO_PUBLIC_DIR;
} else {
    $baseDir = Mage::getBaseDir();
}

```

This logic lives 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 21-25. The chosen `$baseDir` is then concatenated with the request path of each CSS/JS asset to locate the original file on disk.

## Understanding MAHO_PUBLIC_DIR vs Mage::getBaseDir()

### MAHO_PUBLIC_DIR for Maho Installations

**MAHO_PUBLIC_DIR** is a constant defined by the Maho fork of OpenMage that points to the public web-root directory (typically `pub/`). When this constant exists, the module uses it to resolve asset paths relative to the public directory, ensuring correct file location in Maho's separated public structure.

### Mage::getBaseDir() for Standard OpenMage/Magento 1

If **MAHO_PUBLIC_DIR** is not defined, the module falls back to `Mage::getBaseDir()`, which returns the root directory of the Magento installation (the folder containing `app/`, `media/`, `skin/`, etc.). This maintains compatibility with standard OpenMage and legacy Magento 1 environments that use a single-root layout.

## How the Base Directory Is Used for Asset Processing

Once the `$baseDir` variable is set, the observer concatenates it with the request path of each CSS/JS asset to perform several critical operations:

- **File existence checks** using `file_exists()` to verify the original asset exists on disk
- **Modification time retrieval** via `filemtime()` to determine if the minified version needs regeneration
- **Path resolution** for generating minified copies in the `media/fbminify/` folder

This approach ensures the module works seamlessly across both Maho and standard OpenMage installations without requiring manual configuration.

## Summary

- The module detects Maho installations by checking for the `MAHO_PUBLIC_DIR` 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)
- It falls back to `Mage::getBaseDir()` for standard OpenMage and Magento 1 environments
- The chosen base directory is used to locate original CSS/JS files for minification and cache management in `media/fbminify/`
- No manual configuration is required; the module automatically adapts to the underlying platform

## Frequently Asked Questions

### What is MAHO_PUBLIC_DIR?

MAHO_PUBLIC_DIR is a PHP constant defined by the Maho fork of OpenMage that specifies the path to the public web directory (typically `pub/`). The CssjsMinify module checks for this constant to correctly resolve asset paths in Maho's separated public structure.

### Does the module work on standard Magento 1 installations?

Yes, the module fully supports standard Magento 1 and OpenMage installations. When `MAHO_PUBLIC_DIR` is not defined, it automatically falls back to `Mage::getBaseDir()`, which returns the traditional Magento root directory containing the `app`, `skin`, and `media` folders.

### Where does the module store minified files?

The module stores minified CSS and JavaScript files in the `media/fbminify/` directory. This location is used regardless of which base directory (`MAHO_PUBLIC_DIR` or `Mage::getBaseDir()`) is detected, ensuring consistent cache management across different platform variants.

### How do I know which base directory is being used?

The module automatically detects the appropriate base directory at runtime in the `httpResponseSendBefore()` method of the observer class. You can verify which directory is active by checking if the `MAHO_PUBLIC_DIR` constant is defined in your environment; if it exists, the module uses it, otherwise it uses `Mage::getBaseDir()`.