load.php endpoint.
ResourceLoader is a loading system for JavaScript and CSS resources.
— ResourceLoader.php docblock
What ResourceLoader does
Dependency resolution
Modules declare their dependencies. ResourceLoader builds a dependency graph and ensures modules load in the correct order, with deduplication.
Batching
Multiple modules are combined into a single HTTP request, reducing the number of round-trips needed to load a page.
LESS compilation
CSS files may be written in LESS. ResourceLoader compiles LESS to CSS server-side using
wikimedia/less.php before delivery.Minification
JavaScript is minified using
wikimedia/minify (JavaScriptMinifier). CSS is minified using CSSMin.Cache versioning
Each module has a version hash. Browsers cache aggressively via long
max-age headers. When a module changes, its hash changes and the browser fetches the new version.RTL support
CSS is automatically flipped for right-to-left languages using CSSJanus, so extensions don’t need to maintain separate LTR/RTL stylesheets.
The load.php entry point
All resource requests pass throughload.php (handled by ResourceLoaderEntryPoint). A typical request URL looks like:
| Parameter | Description |
|---|---|
modules | Pipe-separated list of module names to load |
lang | User language code |
skin | Active skin name |
only | scripts, styles, or omitted (combined) |
version | Version hash for cache busting |
debug | true to serve unminified code |
Module system
Resources are organized into named modules. A module is a named collection of scripts, styles, messages, templates, and declared dependencies. Modules are defined inextension.json (for extensions), skin.json (for skins), or in resources/Resources.php (for core).
For example, core defines the jquery module as:
mediawiki.base — the foundation of the mw global — as:
Module loading
Modules are loaded client-side viamw.loader. The startup module bootstraps the loader and registers all known module names, version hashes, and dependency graphs in a compact format.
mw.loader.using()
mw.loader.using() returns a promise that resolves when all requested modules (and their transitive dependencies) are loaded and ready:
mw.loader.load()
mw.loader.load() is a fire-and-forget version that starts loading without returning a promise:
Build system
LESS compilation
Stylesheet files can use LESS syntax. ResourceLoader compiles LESS usingwikimedia/less.php. Shared variables and mixins from mediawiki.less/ are available to all modules:
Minification
In production, JavaScript is minified withJavaScriptMinifier and CSS with CSSMin. Both tools are part of the wikimedia/minify library.
The CACHE_VERSION constant in ResourceLoader is bumped whenever the minification output changes in a way that would require cache invalidation:
Debug mode
ResourceLoader has a debug mode that serves unminified, unmerged files with source maps. Enable it for a single request by appending?debug=true to any wiki page URL, or set it globally:
- JavaScript is served without minification.
- Each script file is loaded as a separate request (
debugRawmode). - LESS files are still compiled server-side.
- Source maps are included where available.
Module versioning and caching
Each module has a version hash derived from the content of its files, configuration, and registered messages. When any input to a module changes, its hash changes. ResourceLoader sendsCache-Control: max-age=2592000 (30 days) for versioned responses. Unversioned requests (without a version parameter) receive max-age=5 to allow recovery from errors.
max-age) because it contains the version hashes of all other modules and must stay current.
Module groups
Modules belong to groups that control how they are batched and which pages they load on:| Group constant | Value | Description |
|---|---|---|
Module::GROUP_SITE | site | MediaWiki namespace JS/CSS (MediaWiki:Common.js) |
Module::GROUP_USER | user | Per-user JS/CSS (User:Name/common.js) |
Module::GROUP_PRIVATE | private | Loaded inline, not cacheable |
Module::GROUP_NOSCRIPT | noscript | Loaded in <noscript> blocks |
