Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -220,6 +220,22 @@ |
221 | 221 | $missing[] = $name; |
222 | 222 | } |
223 | 223 | } |
| 224 | + |
| 225 | + // Calculate the mtime of this request. We need this, 304 or no 304 |
| 226 | + $mtime = 1; |
| 227 | + foreach ( $modules as $name ) { |
| 228 | + $mtime = max( $mtime, self::getModule( $name )->getmtime() ); |
| 229 | + } |
| 230 | + header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) ); |
| 231 | + |
| 232 | + // Check if there's an If-Modified-Since header and respond with a 304 Not Modified if possible |
| 233 | + $ims = $request->getHeader( 'If-Modified-Since' ); |
| 234 | + if ( $ims !== false && wfTimestamp( TS_UNIX, $ims ) == $mtime ) { |
| 235 | + header( 'HTTP/1.0 304 Not Modified' ); |
| 236 | + header( 'Status: 304 Not Modified' ); |
| 237 | + return; |
| 238 | + } |
| 239 | + |
224 | 240 | // Use output buffering |
225 | 241 | ob_start(); |
226 | 242 | // A list of registrations will be collected and appended to mediawiki script-only output |
Index: branches/resourceloader/phase3/includes/DefaultSettings.php |
— | — | @@ -1624,6 +1624,19 @@ |
1625 | 1625 | */ |
1626 | 1626 | $wgClockSkewFudge = 5; |
1627 | 1627 | |
| 1628 | +/** |
| 1629 | + * Maximum time in seconds to cache resources served by the resource loader on |
| 1630 | + * the client side (e.g. in the browser cache). |
| 1631 | + */ |
| 1632 | +$wgResourceLoaderClientMaxage = 30*24*60*60; // 30 days |
| 1633 | + |
| 1634 | +/** |
| 1635 | + * Maximum time in seconds to cache resources served by the resource loader on |
| 1636 | + * the server side. This means Squid/Varnish but also any other public proxy |
| 1637 | + * cache between the client and MediaWiki. |
| 1638 | + */ |
| 1639 | +$wgResourceLoaderServerMaxage = 60*60; // 1 hour |
| 1640 | + |
1628 | 1641 | /** @} */ # end of cache settings |
1629 | 1642 | |
1630 | 1643 | /************************************************************************//** |
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -365,7 +365,7 @@ |
366 | 366 | $retval = 1; // wfTimestamp() interprets 0 as "now" |
367 | 367 | foreach ( $jsPages as $jsPage ) { |
368 | 368 | if ( $jsPage->exists() ) { |
369 | | - $retval = max( $retval, $jsPage->getTouched() ); |
| 369 | + $retval = max( $retval, wfTimestamp( TS_UNIX, $jsPage->getTouched() ) ); |
370 | 370 | } |
371 | 371 | } |
372 | 372 | return $retval; |
Index: branches/resourceloader/phase3/load.php |
— | — | @@ -25,8 +25,6 @@ |
26 | 26 | * This file is the entry point for the resource loader. |
27 | 27 | */ |
28 | 28 | |
29 | | -// TODO: Caching + easy 304s before WebStart |
30 | | - |
31 | 29 | require ( dirname( __FILE__ ) . '/includes/WebStart.php' ); |
32 | 30 | wfProfileIn( 'load.php' ); |
33 | 31 | |
— | — | @@ -47,8 +45,12 @@ |
48 | 46 | // FIXME: Doesn't this execute the rest of the request anyway? |
49 | 47 | // Was taken from api.php so I guess it's maybe OK but it doesn't look good. |
50 | 48 | } |
51 | | -// Include core resource list |
52 | | -require_once "$IP/resources/Resources.php"; |
| 49 | + |
| 50 | +// Set caching headers |
| 51 | +$expires = wfTimestamp( TS_RFC2822, min( $wgResourceLoaderClientMaxage, $wgResourceLoaderServerMaxage ) + time() ); |
| 52 | +header( "Cache-Control: public, maxage=$wgResourceLoaderClientMaxage, s-maxage=$wgResourceLoaderServerMaxage" ); |
| 53 | +header( "Expires: $expires" ); |
| 54 | + |
53 | 55 | // Respond to resource loading request |
54 | 56 | ResourceLoader::respond( $wgRequest, $wgServer . $wgScriptPath . '/load.php' ); |
55 | 57 | |