public function loadJsAction()
{
$assets = array();
$md5String = '';
$newestMTime = 0;
$jsContent = '';
foreach ($this->jarves->getConfigs() as $bundleConfig) {
foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
if (!$assetInfo->isJavaScript()) {
continue;
}
if (!$assetInfo->isCompressionAllowed()) {
continue;
}
$path = $this->jarves->resolveWebPath($assetInfo->getPath());
if (file_exists($path)) {
$assets[] = $assetInfo->getPath();
$mtime = filemtime($path);
$newestMTime = max($newestMTime, $mtime);
$md5String .= ">{$path}.{$mtime}<";
$content = file_get_contents($path);
$jsContent .= "\n/* file: {$assetInfo->getPath()} */\n{$content}\n";
}
}
}
$ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $newestMTime) {
// Client's cache IS current, so we just respond '304 Not Modified'.
$response = new Response();
$response->setStatusCode(304);
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $newestMTime) . ' GMT');
return $response;
}
$expires = 60 * 60 * 24 * 14;
//2 weeks
$response = new Response();
$response->headers->set('Content-Type', 'application/javascript');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'max-age=' . $expires);
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
// $content = implode($files);
$response->setContent($jsContent);
return $response;
}