: No mod_expires or mod_headers in apache, how can I cache images/js/css files? Title says it all, we do not have control over our server environment and although we can request for them to recompile
Title says it all, we do not have control over our server environment and although we can request for them to recompile apache for us it will not happen overnight.
Is there anything we can do is these modules (mod_expires, mod_headers) are not available to help with specifying certain content (images, js, css) should be cached or are we out of luck ?
More posts by @Ravi8258870
1 Comments
Sorted by latest first Latest Oldest Best
One option is to send them through a PHP script and have that script out caching headers for you. It accomplishes the same thing with only a little extra overhead for having to have PHP serve the image as a proxy.
Example:
HTML:
<img src="/images/img.php?img=someimage.png">
PHP:
<?php
$filename = $_GET['img'];
$file = '/path/to/file/' . $filename;
// Do verification that the file exists, they're not after any secure
// files, etc. Not shown here
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header("Last-Modified: " . date( "D, j M Y H:i:s", strtotime("- 1 month")));
header("Expires: Thu, 20 Sep 2012 05:00:00 GMT");
header("Cache-Control: max-age=2692000, public");
header("Pragma: cache");
ob_clean();
flush();
readfile($file);
exit;
?>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.