Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mjr Cache Aware Class Loader Laravel Package

modera/mjr-cache-aware-class-loader

A cache-aware PHP class loader for Laravel that speeds up autoloading by caching class lookups and refreshing them when files change. A drop-in replacement for Composer's autoloader aimed at cutting filesystem overhead in larger applications.

View on GitHub
Deep Wiki
Context7

Getting Started

Read this before you install anything: the package name and the description lie. The description calls it a "Laravel/PHP class loader" and shows a plain composer require. The actual source is a Symfony 2.x/3.x bundle — ModeraMjrCacheAwareClassLoaderBundle — that decorates the MJR/ExtJS class-loader HTTP endpoint. It has no laravel/framework constraint, no service provider, no config/ publishable config, no facade. It was split from a monorepo, last tagged 2016-06-10, and the repo is read-only. There is no "day-to-day" in a Laravel app for this package; the honest first step is deciding whether you're evaluating it at all.

If you're still here, your realistic first three steps are:

  1. Confirm the framework mismatch before wasting a sprint. Run:

    composer show -a modera/mjr-cache-aware-class-loader
    

    Look at the type (expect symfony-bundle), require (expect symfony/*, not illuminate/*), and the tags. If you see Symfony constraints, stop — this is not installable in a Laravel app without pulling in a second framework's idioms for one asset concern.

  2. If the target is actually a legacy Symfony/MJR app, look in this order:

    • Resources/config/routing.xml — the route Ext.Loader must be pointed at.
    • Controller/ — the action that computes ETag/Last-Modified and streams the class file.
    • DependencyInjection/Configuration.php — whether any TTL/private/public knobs exist.
    • DependencyInjection/ — the compiler pass or service decorator that replaces MJR's stock loader.

    Register in app/AppKernel.php and import the routing as a Symfony bundle — not as a Laravel service provider:

    new Modera\MjrCacheAwareClassLoaderBundle\ModeraMjrCacheAwareClassLoaderBundle(),
    
  3. If you're on Laravel (the realistic case), your first use case is a 30-minute reference read, not an install. The transferable idea is: a class/asset endpoint should return validators (ETag/Last-Modified) and Cache-Control, and support 304 so repeat loads skip the origin. Implement that idea in Laravel middleware over your own asset route — see Implementation Patterns — rather than trying to vendor a dead Symfony bundle.

Sanity check if you did get it running somewhere legacy:

bin/console debug:router | grep -i mjr
curl -sI 'https://app.local/mjr/class-loader/load?className=Modera.Foo'          # expect ETag, Last-Modified, Cache-Control
curl -sI -H 'If-None-Match: "<etag>"' 'https://app.local/mjr/class-loader/load?className=Modera.Foo'  # expect 304, no body

Implementation Patterns

Since you will not be use-ing this as a package in Laravel, the useful patterns are what to borrow and how to wire the equivalent in a modern stack.

  • Borrow the validator contract, reimplement the endpoint. The bundle's real contribution is: take the requested class name → resolve the file → emit ETag + Last-Modified + long Cache-Control → honour If-None-Match/If-Modified-Since with an empty 304. That is ~20 lines of Laravel middleware over your own route; you do not need the bundle to get it.
    Route::get('/mjr/class-loader/{class}', function (string $class) {
        $path = base_path('vendor/mjr/'.str_replace('.', '/', $class).'.js');
        abort_unless(is_file($path), 404);
        return response()->file($path, [
            'Cache-Control' => 'private, max-age=31536000, immutable',
        ]); // Symfony's BinaryFileResponse sets ETag/Last-Modified and 304 for you
    });
    
  • Version the URL, don't trust time. Stable class URLs are the reason a deploy can serve a half-stale Ext.define. In Laravel, append an assets_version-style token (deploy ID or content hash) to the Ext.Loader path, or purge your CDN/Varnish on release. max-age alone is not an invalidation strategy.
  • Front the app with a shared cache. Per-request validators are worthless if nothing honours them. Either wrap the kernel in HttpCache (Symfony) / your app behind Varnish/CDN, or you're paying for an ETag on every load and getting nothing back.
  • Keep dev uncached. Leave Ext.Loader disableCaching: true (which appends _dc=…) in local/dev and skip the long max-age there. _dc already defeats caching; a stale JS during development is a debugging tax with no upside.
  • Route swap, not a rewrite. If you are on legacy MJR, the correct pattern is: leave MJR's namespace→path mapping alone, change only the URL Ext.Loader requests. That confines the bundle's surface to "compute validators + stream the file."
  • Uniform caching for non-class-loader assets: add a kernel.response listener (or Laravel Terminate/middleware) if you want templates/CSS to share the caching policy — the bundle only covers the class-loader endpoint.

Gotchas and Tips

  • The package name is the biggest gotcha. "Laravel/PHP class loader" + composer require in the description are misleading; the artifact is a Symfony bundle. If you composer require this into a Laravel app you get either a resolver failure or dead weight plus stray Symfony dependencies. Treat the description as aspirational, not accurate.
  • Unmaintained and read-only. Last release 2016, zero stars, zero dependents, no upstream to patch. Pin exactly ("dev-master" or a specific tag) and expect to fork and own it permanently if you insist on adopting — ContainerAware inheritance and untyped Controller::*Action signatures are the usual PHP 8 / Symfony 5+ breakages.
  • Class-name input is attacker-controlled. ?className=… becomes a filesystem path. Verify the action normalizes and confines it (realpath + prefix check), not naive str_replace('.', '/'). If you inherit this, audit and add the guard yourself; there is no maintainer to file a CVE with.
  • private vs public. A public Cache-Control on an authenticated class-loader route leaks class source through any intermediary proxy. Confirm the responses are private or the route is restricted to a trusted network.
  • mtime-based ETags break on a load-balanced cluster. Nodes provisioned at different times emit different Last-Modified for identical content, so clients bounce and re-download. Use a deploy ID / content hash as the validator.
  • 304 must be empty. If you touch the action, return early after $response->setNotModified(); appending a body to a 304 breaks some proxies and Ext's loader.
  • Headers get overwritten downstream. Symfony listeners, the dev profiler, or your own response listener can clobber Cache-Control. Verify with curl -I against the real stack, not just a controller unit test.
  • Namespace mapping is MJR's job, not this bundle's. If classes 404 after a route swap, check Ext.Loader.setPath(...) / the Symfony-side namespace registry before blaming the cache bundle.
  • Decommission signal. If a Modera/MJR dependency shows up in your estate, treat it as a reason to prioritise the ExtJS exit (Vite/Webpack/AssetMapper + CDN cache headers do the same job with a maintained toolchain) rather than extend its life. This bundle is documentary evidence of how the original authors intended caching to work — not a runtime dependency.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core