Effective image caching?
Posted: Fri Jun 12, 2009 6:48 am
Hey everyone,
I've started caching CSS and JavaScript using .htaccess and a auto_prepend_file, and was wondering why the same technique isn't working for images? For example:
/css/.htaccess
/css/gzip-css.php
The code above works fine, however I'm trying the same approach for /img and I've hit a bit of a roadblock. Here's a sample for PNG:
/img/.htaccess
/img/gzip-png.php
But that doesn't work, the images disappear from the page. Can anyone see what I'm doing wrong? Incidentally /img contains only directories - could this be the problem?
Thanks and regards, Ben
I've started caching CSS and JavaScript using .htaccess and a auto_prepend_file, and was wondering why the same technique isn't working for images? For example:
/css/.htaccess
Code: Select all
AddHandler application/x-httpd-php .css
php_value auto_prepend_file gzip-css.phpCode: Select all
<?php
ob_start('ob_gzhandler');
header('Content-type: text/css; charset: UTF-8');
header('Cache-Control: must-revalidate');
header('Expires: '.gmdate('D, d M Y H:i:s', time()+(60*60*24)).' GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s", time()-(60*60*24)).' GMT'); // not too sure if this is naughty
?>/img/.htaccess
Code: Select all
AddHandler application/x-httpd-php .png
php_value auto_prepend_file gzip-png.phpCode: Select all
<?php
ob_start('ob_gzhandler');
header('Content-type: image/png');
header('Cache-Control: must-revalidate');
header('Expires: '.gmdate('D, d M Y H:i:s', time()+(60*60*24)).' GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s", time()-(60*60*24)).' GMT');
?>Thanks and regards, Ben