You are here

function advagg_file_download in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg.module \advagg_file_download()

Implements hook_file_download().

Return the correct headers for advagg bundles.

File

./advagg.module, line 3348
Advanced CSS/JS aggregation module

Code

function advagg_file_download($file, $type = '') {

  // Do nothing if not an AdvAgg File.
  if (strpos($file, '/advagg_') === FALSE || empty($type)) {
    return;
  }

  // Set the headers.
  $return = array();
  $return[] = 'Content-Length: ' . filesize($file);

  // Set a far future Cache-Control header (480 weeks), which prevents
  // intermediate caches from transforming the data and allows any
  // intermediate cache to cache it, since it's marked as a public resource.
  $return[] = "Cache-Control: max-age=290304000, no-transform, public";

  // Set a far future Expires header. The maximum UNIX timestamp is somewhere
  // in 2038. Set it to a date in 2037, just to be safe.
  $return[] = 'Expires: Tue, 20 Jan 2037 04:20:42 GMT';

  // Pretend the file was last modified a long time ago in the past, this will
  // prevent browsers that don't support Cache-Control nor Expires headers to
  // still request a new version too soon (these browsers calculate a
  // heuristic to determine when to request a new version, based on the last
  // time the resource has been modified).
  // Also see http://code.google.com/speed/page-speed/docs/caching.html.
  $return[] = 'Last-Modified: Wed, 20 Jan 1988 04:20:42 GMT';
  if ($type == 'css') {
    $return[] = 'Content-Type: text/css';
  }
  if ($type == 'js') {
    $return[] = 'Content-Type: text/javascript';
  }
  return $return;
}