Showing posts with label cache control. Show all posts
Showing posts with label cache control. Show all posts

Monday, July 07, 2008

enable mod expire for fast image loading

here is the example from google (they have set the cache expire far far in the future )


$ curl -I http://www.google.ro/logos/chagall.gif

HTTP/1.1 200 OK
Content-Type: image/gif
Last-Modified: Mon, 07 Jul 2008 04:33:28 GMT
Expires: Sun, 17 Jan 2038 19:14:07 GMT
Cache-Control: public
Date: Mon, 07 Jul 2008 10:09:52 GMT
Server: gws
Content-Length: 16715


here is my configure.nice script for apache 2.2.x

"./configure" \
"--prefix=/opt/apache2.2" \
"--enable-so" \
"--enable-mantainer-mode" \
"--enable-module=all" \
"--enable-rewrite" \
"--enable-include" \
"--enable-info" \
"--enable-expires" \
"$@"

also after all is build and installed (apache server restarted)
you can check the expire config

$/opt/apache2.2/bin/httpd -l | grep expire

or in browser
http://example.com/server-info?mod_expires.c

and add the expire config into the httpd.conf or .htaccess

ExpiresByType text/html "access plus 1 month 15 days 2 hours"
ExpiresByType image/gif "
access plus 1 month 15 days 2 hours"

you can check later the expire headers with curl

$curl -I http://example.com/images/example.gif

HTTP/1.1 200 OK
Date: Mon, 07 Jul 2008 12:18:14 GMT
Server: Apache/2.2.8 (Unix) PHP/5.2.6
Last-Modified: Tue, 01 Jul 2008 13:57:59 GMT
ETag: "3884a9-2348f-450f6c38087c0"
Accept-Ranges: bytes
Content-Length: 144527
Cache-Control: max-age=3895200
Expires: Thu, 21 Aug 2008 14:18:14 GMT
Content-Type: image/gif