Forum Moderators: phranque

Message Too Old, No Replies

Need some mod expires help

Using mod_expires for the first time and I am not sure if it's working

         

sylvian

7:43 pm on Feb 23, 2011 (gmt 0)

10+ Year Member



Hi

I am using mod_expires for the first time. I have added the following to the .htaccess file but I am not sure that anything has changed:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 hours"
ExpiresByType text/css "modification plus 1 week"
ExpiresByType text/js "modification plus 1 year"
ExpiresByType application/x-javascript "modification plus 1 year"
ExpiresByType image/gif "modification plus 1 year"
ExpiresByType image/jpeg "modification plus 1 year"
ExpiresByType image/ico "modification plus 1 week"
</IfModule>


I checked with the host and they verified that mod_expires is running. I use the WebDeveloper plugin for Firefox to check the header response. I expected to see some additional lines in the header, but maybe I am just not reading it correctly. The following is what I got, for an image and for a page, respectively:

Date: Wed, 23 Feb 2011 19:34:16 GMT
Server: Apache/1.3.41 (Unix) mod_gzip/1.3.26.1a mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.7a
Cache-Control: max-age=2136119
Expires: Sun, 20 Mar 2011 12:56:15 GMT
Last-Modified: Sat, 20 Mar 2010 12:56:15 GMT
Etag: "a4814b-47da-4ba4c5ef"
Accept-Ranges: bytes
Content-Length: 18394
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: image/jpeg
200 OK


Date: Wed, 23 Feb 2011 19:40:31 GMT
Server: Apache/1.3.41 (Unix) mod_gzip/1.3.26.1a mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.7a
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Content-Length: 7289
200 OK


So, again, I just want to verify that my .htaccess code is working.

Thanks

jdMorgan

7:05 pm on Mar 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like mod_expires is not installed on your server then. You should be seeing a "Cache-Control" header in the responses from your server. Ask your host.

If mod_expires is not available, then perhaps you might have mod_headers support. If so, you could manually create the headers by enclosing "Header set" directives within <Files> or <FilesMatch> containers. Example:

<FilesMatch "\.gif$">
Header set Cache-Control: "max-age=86400"
</FilesMatch>

Your expires times appear to be far too long -- and dangerously so in the case of javascripts and images. I strongly suggest setting expires times no longer than one week on any filetypes which might *ever* conceivably change.

Caching for one hour saves a lot of bandwidth. Caching for four hours saves a little more, and caching for a day saves a tiny bit more than that. But the difference in bandwidth saving between an expires time of one week and one month --or between one month and one year-- is going to be essentially zero.

And at that point, you're running the risk that some user whose browser has just cached your javascript will continue to run bad code for 364 days after you fixed a bug...

Jim