Does the OpenMage CSS/JS Minify Module Process External CSS or JS URLs?

No, the OpenMage CSS/JS Minify module only processes locally-hosted files and ignores external CDN URLs.

The OpenMage CSS/JS Minify extension is designed to reduce page load times by minifying CSS and JavaScript assets. However, its architecture strictly limits processing to files that exist on the local Magento filesystem, leaving external resources from CDNs or third-party domains completely untouched.

How the Module Detects and Processes Assets

The module operates by observing the http_response_send_before event and scanning the final HTML output for resource tags. The core logic resides in app/code/community/Fballiano/CssjsMinify/Model/Observer.php.

The HTML Parsing Logic

The observer uses regular expressions to extract resource URLs from the HTML response. At lines 38‑40, the module captures JavaScript sources:

// Regex pattern for JS files
preg_match_all('/<script[^>]+src=["\']([^"\']+)["\']/', $html, $matches);

Similarly, at lines 68‑70, it captures CSS links:

// Regex pattern for CSS files
preg_match_all('/<link[^>]+href=["\']([^"\']+)["\']/', $html, $matches);

The Local File Existence Check

After extracting the URL, the module determines whether to process the file by checking its existence on the local server. At line 44 (for JS) and line 74 (for CSS), the code executes:

$path = parse_url($url, PHP_URL_PATH);
if (file_exists($baseDir . $path)) {
    // Proceed with minification
}

If file_exists() returns false, the module returns the original HTML tag unchanged, effectively skipping any processing for that resource.

Why External CDN URLs Are Skipped

When the module encounters an external URL such as https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js, the parse_url() function extracts the path component as /ajax/libs/jquery/3.6.0/jquery.min.js. The subsequent file_exists() check looks for this path relative to the Magento base directory (e.g., /var/www/html/ajax/libs/jquery/3.6.0/jquery.min.js).

Since this file does not exist on the local filesystem, the condition fails and the module leaves the original CDN URL intact in the HTML output. This design prevents the module from attempting to download, cache, or modify remote resources, focusing solely on locally manageable assets.

Code Examples: Local vs. External Resources

The following examples illustrate which resources get minified and which remain unchanged:

Local files that WILL be minified:

<!-- These resolve to local files and will be processed -->
<link rel="stylesheet" href="/skin/frontend/base/default/css/styles.css">
<script src="/js/custom/script.js"></script>

External CDN files that will NOT be minified:

<!-- These are external URLs and will be ignored -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

For local files, the module creates minified copies in media/fbminify/ and rewrites the HTML to point to these optimized versions. External resources remain referenced by their original URLs.

Summary

  • The OpenMage CSS/JS Minify module only processes assets stored on the local Magento filesystem.
  • It uses file_exists() checks in Observer.php (lines 44 and 74) to verify local file presence before minification.
  • External CDN URLs fail the local file check and are returned unchanged in the HTML output.
  • Minified local files are stored in media/fbminify/ with rewritten URLs in the final response.

Frequently Asked Questions

Does the module download external files for minification?

No. The module does not implement any remote fetching logic. It strictly checks for file existence on the local server using file_exists($baseDir . $path) and skips any resources that do not resolve to local paths.

Can I force the module to minify CDN resources?

No. The current implementation in app/code/community/Fballiano/CssjsMinify/Model/Observer.php does not support downloading or caching external files. To minify CDN resources, you would need to download them to your local filesystem and reference them via local paths instead of external URLs.

What happens to external URLs in the final HTML?

External URLs remain completely unchanged in the HTML output. When the file_exists check fails for an external URL, the observer returns the original tag verbatim, preserving the original CDN or third-party domain reference.

Where are minified local files stored?

Minified files are stored in the media/fbminify/ directory within your Magento installation. The module creates this directory structure automatically and rewrites the HTML tags to reference these optimized versions using the media/fbminify/ path prefix.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →