Forum Moderators: coopster
<?php
ob_start();
echo '//<![CDATA['."\n";
$file = array('file1.js','file2.js','file3.js','file4.js');
$latest = getlastmod();
foreach ($file as $key => $value)
{
$mod = filemtime($value);
if ($mod>$latest) {$latest = $mod;}
include($value);
}
echo '//]]>';
$buffer = ob_get_contents();
ob_end_clean();
$lastmod = gmdate('D, d M Y H:i:s',$latest);
header('Last-Modified: '.$lastmod.' GMT');
$exp0 = $latest + 120;//Two Minutes
$exp1 = gmdate('D, d M Y H:i:s',$exp0).' GMT';
header('Expires: '.$exp1);
header('Cache-Control: max-age=120');//Two Minutes
function cacheHeaders($lastModifiedDate)
{
if ($lastModifiedDate)
{
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModifiedDate)
{
header('HTTP/1.1 304 Not Modified');
die;
}
else
{
$gmtDate = gmdate('D, d M Y H:i:s\G\M\T',$lastModifiedDate);
header('Last-Modified: '.$gmtDate);
}
}
}
cacheHeaders($latest);
header('content-type:application/javascript');
ob_start('ob_gzhandler');
echo $buffer;
ob_end_flush();
?>