PHPackages                             zwernemann/magento2-minresolver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zwernemann/magento2-minresolver

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

zwernemann/magento2-minresolver
===============================

Fixes intermittent \*.min.js 404 errors (e.g. globals.js) caused by stale baseUrl and double-wrapping of the RequireJS min-resolver in Magento 2.

1.0.0(3mo ago)04MITPHPPHP &gt;=7.4.0

Since Mar 24Pushed 3mo agoCompare

[ Source](https://github.com/Zwernemann/magento2-minResolver)[ Packagist](https://packagist.org/packages/zwernemann/magento2-minresolver)[ RSS](/packages/zwernemann-magento2-minresolver/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

magento2-minResolver
====================

[](#magento2-minresolver)

A drop-in patch for Magento 2 that fixes intermittent 404 errors caused by RequireJS loading plain `.js` files instead of `.min.js` when JavaScript minification is enabled in the Admin panel.

Tested on Magento **2.4.7-p9**.

---

The Problem
-----------

[](#the-problem)

### What you see

[](#what-you-see)

With **Minify JavaScript Files** enabled (Admin → Stores → Config → Advanced → Developer → JavaScript Settings), Magento Admin works fine most of the time. But after navigating back and forth several times — for example between Sales → Orders and Create Order — the browser console suddenly shows:

```
GET /static/version.../adminhtml/.../mage/adminhtml/globals.js
    net::ERR_ABORTED 404 (Not Found)

```

The page may partially break: grids don’t load, buttons stop responding, or JavaScript errors cascade. A hard reload fixes it temporarily — until it happens again.

### Why is it intermittent?

[](#why-is-it-intermittent)

The bug does not appear on the first page load. It surfaces only after several AJAX navigations within the same browser session. A single smoke test is unlikely to catch it.

---

Root Causes
-----------

[](#root-causes)

Magento ships a small script called `requirejs-min-resolver.min.js` that is injected into every Admin page. Its job is to force RequireJS to always request `.min.js` URLs. The original implementation contains two defects.

### Defect 1 — Stale `baseUrl` closure

[](#defect-1--stale-baseurl-closure)

```
// Original Magento code
(function() {
    var ctx = require.s.contexts._,
        origNameToUrl = ctx.nameToUrl,
        baseUrl = ctx.config.baseUrl;  // captured ONCE at script-load time

    ctx.nameToUrl = function() {
        var url = origNameToUrl.apply(ctx, arguments);
        if (url.indexOf(baseUrl) === 0   // compared against the stale value
            && !url.match(/\/hugerte\//)
            && !url.match(/\/v1\/songbird/)) {
            url = url.replace(/(\.min)?\.js$/, '.min.js');
        }
        return url;
    };
}());
```

`baseUrl` is captured once when the script first runs. During AJAX navigation Magento can reconfigure RequireJS. After reconfiguration `ctx.config.baseUrl` has a new value, but the closed-over `baseUrl` variable is still the old one. The `indexOf` check fails for every URL, the `.min.js` rewrite is skipped, and the browser requests the plain `.js` file — which does not exist — resulting in a 404.

### Defect 2 — Double-wrapping on re-evaluation

[](#defect-2--double-wrapping-on-re-evaluation)

On AJAX navigation the Admin can re-inject and re-evaluate `requirejs-min-resolver.min.js`. Each evaluation runs `ctx.nameToUrl = function() { ... origNameToUrl ... }` where `origNameToUrl`was captured from the *current* `ctx.nameToUrl` — which is already the patched version from the previous evaluation. The result is a growing chain:

```
patch3( patch2( patch1( original ) ) )

```

With no idempotency guard, each additional wrapper can alter the URL differently, potentially producing wrong paths or double-suffixed filenames like `globals.min.min.js`.

---

The Fix
-------

[](#the-fix)

A single self-contained IIFE that closes both gaps:

```
(function(){

  function patchCtx(c){
    if(!c||c.__mRF)return;   // idempotency guard — never patch twice
    c.__mRF=true;
    var p=c.nameToUrl;
    c.nameToUrl=function(){
      // baseUrl read dynamically on every call — never goes stale
      var u=p.apply(c,arguments),b=c.config&&c.config.baseUrl;
      if(b&&u.indexOf(b)===0
        &&!/\.min\.js$/.test(u)
        &&!/\/hugerte\//.test(u)
        &&!/\/v1\/songbird/.test(u)){
        u=u.replace(/\.js$/,'.min.js');
      }
      return u;
    };
  }

  // Layer 1 — patch every context that exists right now (including _)
  var ctxs=require.s.contexts;
  for(var n in ctxs){
    if(Object.prototype.hasOwnProperty.call(ctxs,n))patchCtx(ctxs[n]);
  }

  // Layer 2 — patch every context created from this point on
  if(!require.s.__mNCF){
    require.s.__mNCF=true;
    var oNC=require.s.newContext;
    require.s.newContext=function(){
      var c=oNC.apply(this,arguments);
      patchCtx(c);
      return c;
    };
  }

  // Layer 3 — rewrite the URL at the last possible moment before the XHR fires
  if(!require.__mRL){
    require.__mRL=true;
    var ol=require.load;
    require.load=function(c,m,u){
      var b=c&&c.config&&c.config.baseUrl;
      if(b&&u&&u.indexOf(b)===0
        &&/\.js$/.test(u)&&!/\.min\.js$/.test(u)
        &&!/\/hugerte\//.test(u)&&!/\/v1\/songbird/.test(u)){
        u=u.replace(/\.js$/,'.min.js');
      }
      return ol.call(this,c,m,u);
    };
  }

  console.info('[rjsFix] v6 active');
}());
```

### How each defect is addressed

[](#how-each-defect-is-addressed)

DefectOriginalFixStale `baseUrl`Captured once in outer closureRead as `c.config.baseUrl` inside the function on every callDouble-wrappingNo guard`__mRF` flag on each context prevents patching more than once### Additional layers

[](#additional-layers)

LayerWhat it coversContext loop at load timeAll RequireJS contexts already present, including `_``newContext` hookEvery new named context created after the script runs`require.load` hookLast-resort safety net — rewrites the URL just before the XHR fires`__mNCF` / `__mRL` flagsEnsure the `newContext` and `load` hooks are installed exactly once### Exclusions

[](#exclusions)

`hugerte` and `v1/songbird` are third-party libraries that ship only as unminified JS and must not be rewritten.

---

Compatibility
-------------

[](#compatibility)

- Magento 2.4.x (tested on 2.4.7-p9)
- Only active when **Minify JavaScript Files** is enabled; has no effect otherwise

---

Confirmed Magento Core Issues
-----------------------------

[](#confirmed-magento-core-issues)

IssueDescription[\#38829](https://github.com/magento/magento2/issues/38829)JS Minification &amp; RequireJS loading in production 2.4.7 — both `.min` and non-min files are requested simultaneously[\#38117](https://github.com/magento/magento2/issues/38117)`requirejs-min-resolver.min.js` not generated on `setup:static-content:deploy` — navigation fails after first page load---

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require zwernemann/magento2-minresolver
bin/magento module:enable Zwernemann_MinResolver
bin/magento setup:upgrade
bin/magento setup:static-content:deploy
bin/magento cache:flush
```

### Manually

[](#manually)

Copy `app/code/Zwernemann/MinResolver` to your Magento installation, then:

```
bin/magento module:enable Zwernemann_MinResolver
bin/magento setup:upgrade
bin/magento setup:static-content:deploy
bin/magento cache:flush
```

Compatibility
-------------

[](#compatibility-1)

- Magento 2.3.x, 2.4.x
- PHP 7.4+

License
-------

[](#license)

MIT

Contact
-------

[](#contact)

**Zwernemann Medienentwicklung**
Martin Zwernemann
79730 Murg, Germany

[To the website](https://www.zwernemann.de/)

If you have questions, problems, or ideas for new features – feel free to get in touch.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab806201fa0b72cada23b094f57e8d6e96aca483badab47bf710dfd2f2e19f4b?d=identicon)[Zwernemann](/maintainers/Zwernemann)

---

Top Contributors

[![Zwernemann](https://avatars.githubusercontent.com/u/52236002?v=4)](https://github.com/Zwernemann "Zwernemann (15 commits)")

---

Tags

magento2magento2-module

### Embed Badge

![Health badge](/badges/zwernemann-magento2-minresolver/health.svg)

```
[![Health](https://phpackages.com/badges/zwernemann-magento2-minresolver/health.svg)](https://phpackages.com/packages/zwernemann-magento2-minresolver)
```

###  Alternatives

[elgentos/regenerate-catalog-urls

Regenerate Catalog URL Rewrites (products, categories, cms pages)

2842.6M](/packages/elgentos-regenerate-catalog-urls)[run-as-root/magento2-prometheus-exporter

Magento2 Prometheus Exporter

68353.9k](/packages/run-as-root-magento2-prometheus-exporter)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1859.0k](/packages/myparcelnl-magento)[loki/magento2-components

Core module for defining Alpine.js components with advanced AJAX features

1010.0k22](/packages/loki-magento2-components)[magepal/magento2-form-field-manager

Customer and Address Form Fields Manager for Magento2

273.9k](/packages/magepal-magento2-form-field-manager)[mage-os/module-llm-txt

AI-powered LLMs.txt generation for Magento 2 / Mage-OS stores. Help AI systems understand your store with OpenAI-generated content.

223.3k](/packages/mage-os-module-llm-txt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
