Image expire time

Posted by Jens on Stack Overflow See other posts from Stack Overflow or by Jens
Published on 2010-05-29T07:41:22Z Indexed on 2010/05/29 7:42 UTC
Read the original article Hit count: 202

Filed under:
|
|

The google page speed tool recommends me to set 'Expires' headers for images etc. But what is the most efficient way to set an Expires header for an image?

In now redirect all image requests to an imagehandler.php using htaccess:

/*
HTTP/1.1 404 Not Found, HTTP/1.1 400 Bad Request and content type detection stuff
...
*/

header( "Content-Type: " . $content_type );
header( "Cache-Control: public" );
header( "Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($path))." GMT");
header( "Expires: ". date("r",time() + (60*60*24*30)));
readfile( $path );

But of course this adds extra loading time for my images on first request, and I was wondering if there was a better solution for this.

© Stack Overflow or respective owner

Related posts about php

Related posts about image