< ResourceLoader
RequirementFeaturesBenefitsIssues
Debugging
Support direct resource inclusionAllows JS resources to be included individually and without being run through the loader softwareJS resources can be more easily debugged because file names and line numbers correspond to the actual JS resourcesRequires L10n fallbacks to be embedded in JS resources
Support stand-alone use of loaderAllows the script loader system to be integrated into other frameworks or used as a stand-alone serviceDevelopment efforts can be shared with non-MediaWiki developers, and those developers' efforts can benefit usMakes MediaWiki integration difficult, makes code more foreign to MediaWiki developers
Useful information on loading failureProvides useful, verbose information about failures to load resourcesMakes development easierRequires more code to be written
Packaging
Remove debug statementsAllows JS resources to contain debug information which is stripped out before being sent to the clientDebug information can remain in JS resources for future useMore moving parts to break
JS/CSS MinificationStrips whitespace and comments from JS and CSS resourcesReduces the amount of data sent to the clientMakes debugging more difficult
JS Closure CompilationSimplifies and aggressively optimizes JS functionsReduces the amount of data sent to the client, and improves the performance of many JS functionsMakes debugging very difficult
CSS Janus transformationFlips CSS rules to make LTR stylesheets appropriate for RTLNo need to keep separate files around for this if we can apply this transformation in PHP along with the othersMakes it slightly more difficult to figure out what the RTL version of a given CSS file looks like
Resource batching / concatenationMultiple resources can be included in a single requestReduces the number of requests from clientsPotentially increases cache size, potentially causes double inclusion of resources
Parameterize batched loadingSet a URL param to indicate we need resources for a certain combination of prefs/logged-in-ness rather than detecting this on the serverEliminates the need for uncacheable-for-logged-in-users Vary: Cookie responsesIncreases the number of URL variants
Web-server-level resource cachingCaches processed (localized, minified, etc.) scripts on the serverMakes it faster to batch resources in different combinationCaching is not free, it takes time and space
Use short client-side expiry timesTells clients to refresh cached resources in short intervals (~1h)Eliminates the need to expire HTML (expensive) to force clients to refresh resourcesRequires that RL requests be cheap, so they should support 304 and be cached in Squid
Use highest-timestamp versioning schemeVersion each RL request with the highest last-modified timestamp of the resources involved, formatted in ISO 8601 and rounded to 10sNo more manual style versions. 10s rounding and human-readable format allows faster and easier purging of bad resources from SquidMay cause conflicts when new JS is served with old HTML, need to code around that in JS
In-place localizationIncludes localized messages directly within JS resourcesAllows i18n of JS software without adding additional requestsMixes i18n work with development work
Localization APIMakes messages available on demand individually or in groupsProvides yet another option for getting L10n to the clientVery inefficient way to get L10n to the client
Separate message resource systemGenerates JS blobs for l10n separately, stores them in the DBOnly relevant JS is regenerated when a message changesMakes stand-alone usage more difficult
Export user preferences to JS
CSS grouping (without JS)
CSS includes registered in JS namespaceAllows JS resources to check existence of CSS resources and require CSS resources to be loaded before proceedingFewer CSS resources need to be included initially and modules can safely avoid re-loading already-loaded CSS resourcesRequires more code to be written
Resource bucketsAllows resources to be grouped into buckets such as "all", "view", "edit", etc.Reduces number of individual requests neededPotentially too many things will get put in these buckets
Runtime loading of JS and CSSAllows resources to be included dynamicallyReduces the initial payload sent to clientsPotentially presents delay between user action and resource availability
Module based loadingResources are identified by module namesProvides a standard way of expressing requirements and checking what resources are already loaded
Module loadersModules each have associated loader functions which are executed to load the moduleProvides more flexibility in loadingIncreases the amount of code sent to the client and level of complexity in development
Configurable URL schemeAllows flexibility in request URL formatsMakes using a localhost, web-server or CDN a matter of configuration
Allow version aliasingIn the case that a buggy version of a script is released, a version redirect can be put in placeAvoids purging PHP generated HTML to resolve JS bugsPotentially introduces level of indirection causing negative performance impact. Not needed if scripts are versioned and cached in Squid
Dependency order preservationAllows dependencies to automatically be included in a specific order if neededMakes dependencies simpler to useMay make dependency specification more complex
Structure
Clear division of librariesMakes JS resources communicate with each other using well documented APIsImproves the re-usability of JS resourcesTakes more time to develop and document
Control a specific JS namespaceSpecifies a unified naming convention and access point for JS resourcesImproves maintainability and reduces difficulty to learn the systemRequires porting existing code to conform
Control naming between PHP and JS resourcesSpecifies clear naming between PHP extensions and JS modulesImproves maintainability and reduces difficulty to learn the systemRequires porting existing code to conform
Package-level dependency resolutionJS modules can form packages, which can then be required/included as a wholeReduces complexity of specifying requirements making development easierReduces specificity of requirements potentially causing resources to be loaded that will not be used
Map files, buckets and dependencies in PHPHave an associative array structure in PHP that defines objects, which optionally contain a file and optionally have dependenciesMakes for fewer distinct URLs (?), which eases caching and purgingLimited support for JS-based conditions, would have to be done through parameterization, cannot scale to user scripts
Division between loading and executionJS modules can be loaded on demand, and executed independentlyMakes dependencies simpler to useMakes writing modules more complex
Allow explicit re-loadingResources are not loaded more than once by default, but can be re-loaded if desiredMakes overwriting/re-loading possible/easier
jQuery should be the primary way of extending functionality
jQuery plug-ins should be centrally organizedAll jQuery plug-ins should be committed to a central place, with version numbers in their namesMakes sharing plug-ins easier / more likely to happen and everyone benefits from bug-fixes equallyCauses issues with maintaining extensions or if people cloud the plug-in folder with low-quality plug-ins
JS module version conflict managementMakes module version information available to JS resourcesMakes it possible to migrate to newer versions of plug-ins over timeSends more data to the client, adds complexity to configuration
Utilities
JS localization functionsJS facilities for handling 18n functionality such as {{PLURAL}} and $ replacementMessages can be more flexible and reusableMust be maintained in parallel with PHP i18n functions, limitations must be well understood by translators

Sources

This document is a synthesis of the following sources

This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.