* Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
*
* Available filters are:
- * - minify-js \see JSMin::minify
+ * - minify-js \see JavaScriptDistiller::stripWhiteSpace
* - minify-css \see CSSMin::minify
*
* If $data is empty, only contains whitespace or the filter was unknown,
* @return String: Filtered data, or a comment containing an error message
*/
protected function filter( $filter, $data ) {
+ global $wgResourceLoaderMinifyJSVerticalSpace;
+
wfProfileIn( __METHOD__ );
// For empty/whitespace-only data or for unknown filters, don't perform
try {
switch ( $filter ) {
case 'minify-js':
- $result = JSMin::minify( $data );
+ $result = JavaScriptDistiller::stripWhiteSpace(
+ $data, $wgResourceLoaderMinifyJSVerticalSpace
+ );
break;
case 'minify-css':
$result = CSSMin::minify( $data );
wfProfileIn( __METHOD__.'-getModifiedTime' );
+ $private = false;
// To send Last-Modified and support If-Modified-Since, we need to detect
// the last modified time
$mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
foreach ( $modules as $module ) {
try {
- // Bypass squid cache if the request includes any private modules
+ // Bypass Squid and other shared caches if the request includes any private modules
if ( $module->getGroup() === 'private' ) {
- $smaxage = 0;
+ $private = true;
}
// Calculate maximum modified time
$mtime = max( $mtime, $module->getModifiedTime( $context ) );
}
header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) );
if ( $context->getDebug() ) {
- header( 'Cache-Control: must-revalidate' );
+ // Do not cache debug responses
+ header( 'Cache-Control: private, no-cache, must-revalidate' );
+ header( 'Pragma: no-cache' );
} else {
- header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
- header( 'Expires: ' . wfTimestamp( TS_RFC2822, min( $maxage, $smaxage ) + time() ) );
+ if ( $private ) {
+ header( "Cache-Control: private, max-age=$maxage" );
+ $exp = $maxage;
+ } else {
+ header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
+ $exp = min( $maxage, $smaxage );
+ }
+ header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp + time() ) );
}
// If there's an If-Modified-Since header, respond with a 304 appropriately