Mobile app version of vmapp.org
Login or Join
Ravi8258870

: 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

@Ravi8258870

Posted in: #Cache #CacheControl #StaticContent

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 ?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kristi941

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;

?>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme