resourceloader: Minify per-module instead of per-response
* Decline to cache minified private modules, because they exist in as many variants as there are users, and are unlikely to be cache hits now that we use APC. * Other modules are minified individually, to improve cache hit rate. Bug: T107377 Change-Id: Id6f5142062d73b5701126724e0fe8264105f7813
This commit is contained in:
parent
926a0bfa50
commit
b7eb243d92
1 changed files with 24 additions and 21 deletions
|
|
@ -999,9 +999,13 @@ MESSAGE;
|
||||||
|
|
||||||
// Generate output
|
// Generate output
|
||||||
$isRaw = false;
|
$isRaw = false;
|
||||||
|
|
||||||
|
$filter = $context->getOnly() === 'styles' ? 'minify-css' : 'minify-js';
|
||||||
|
|
||||||
foreach ( $modules as $name => $module ) {
|
foreach ( $modules as $name => $module ) {
|
||||||
try {
|
try {
|
||||||
$content = $module->getModuleContent( $context );
|
$content = $module->getModuleContent( $context );
|
||||||
|
$strContent = '';
|
||||||
|
|
||||||
// Append output
|
// Append output
|
||||||
switch ( $context->getOnly() ) {
|
switch ( $context->getOnly() ) {
|
||||||
|
|
@ -1009,10 +1013,10 @@ MESSAGE;
|
||||||
$scripts = $content['scripts'];
|
$scripts = $content['scripts'];
|
||||||
if ( is_string( $scripts ) ) {
|
if ( is_string( $scripts ) ) {
|
||||||
// Load scripts raw...
|
// Load scripts raw...
|
||||||
$out .= $scripts;
|
$strContent = $scripts;
|
||||||
} elseif ( is_array( $scripts ) ) {
|
} elseif ( is_array( $scripts ) ) {
|
||||||
// ...except when $scripts is an array of URLs
|
// ...except when $scripts is an array of URLs
|
||||||
$out .= self::makeLoaderImplementScript( $name, $scripts, array(), array(), array() );
|
$strContent = self::makeLoaderImplementScript( $name, $scripts, array(), array(), array() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'styles':
|
case 'styles':
|
||||||
|
|
@ -1020,10 +1024,10 @@ MESSAGE;
|
||||||
// We no longer seperate into media, they are all combined now with
|
// We no longer seperate into media, they are all combined now with
|
||||||
// custom media type groups into @media .. {} sections as part of the css string.
|
// custom media type groups into @media .. {} sections as part of the css string.
|
||||||
// Module returns either an empty array or a numerical array with css strings.
|
// Module returns either an empty array or a numerical array with css strings.
|
||||||
$out .= isset( $styles['css'] ) ? implode( '', $styles['css'] ) : '';
|
$strContent = isset( $styles['css'] ) ? implode( '', $styles['css'] ) : '';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$out .= self::makeLoaderImplementScript(
|
$strContent = self::makeLoaderImplementScript(
|
||||||
$name,
|
$name,
|
||||||
isset( $content['scripts'] ) ? $content['scripts'] : '',
|
isset( $content['scripts'] ) ? $content['scripts'] : '',
|
||||||
isset( $content['styles'] ) ? $content['styles'] : array(),
|
isset( $content['styles'] ) ? $content['styles'] : array(),
|
||||||
|
|
@ -1032,6 +1036,17 @@ MESSAGE;
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !$context->getDebug() ) {
|
||||||
|
// Don't cache private modules. This is especially important in the case
|
||||||
|
// of modules which change every time they are built, like the embedded
|
||||||
|
// user.tokens module (bug T84960).
|
||||||
|
$filterOptions = array( 'cache' => ( $module->getGroup() !== 'private' ) );
|
||||||
|
$strContent = $this->filter( $filter, $strContent, $filterOptions );
|
||||||
|
}
|
||||||
|
|
||||||
|
$out .= $strContent;
|
||||||
|
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
MWExceptionHandler::logException( $e );
|
MWExceptionHandler::logException( $e );
|
||||||
$this->logger->warning( 'Generating module package failed: {exception}', array(
|
$this->logger->warning( 'Generating module package failed: {exception}', array(
|
||||||
|
|
@ -1058,7 +1073,11 @@ MESSAGE;
|
||||||
|
|
||||||
// Set the state of modules we didn't respond to with mw.loader.implement
|
// Set the state of modules we didn't respond to with mw.loader.implement
|
||||||
if ( count( $states ) ) {
|
if ( count( $states ) ) {
|
||||||
$out .= self::makeLoaderStateScript( $states );
|
$stateScript = self::makeLoaderStateScript( $states );
|
||||||
|
if ( !$context->getDebug() ) {
|
||||||
|
$stateScript = $this->filter( 'minify-js', $stateScript );
|
||||||
|
}
|
||||||
|
$out .= $stateScript;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( count( $states ) ) {
|
if ( count( $states ) ) {
|
||||||
|
|
@ -1067,22 +1086,6 @@ MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$enableFilterCache = true;
|
|
||||||
if ( count( $modules ) === 1 && reset( $modules ) instanceof ResourceLoaderUserTokensModule ) {
|
|
||||||
// If we're building the embedded user.tokens, don't cache (T84960)
|
|
||||||
$enableFilterCache = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$context->getDebug() ) {
|
|
||||||
if ( $context->getOnly() === 'styles' ) {
|
|
||||||
$out = $this->filter( 'minify-css', $out );
|
|
||||||
} else {
|
|
||||||
$out = $this->filter( 'minify-js', $out, array(
|
|
||||||
'cache' => $enableFilterCache
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue