Forum Moderators: phranque
My current settings ("Cache-Control: no-cache") respond like this:
(compares file modification date with server modification date to see if he has to bring a newer version)
http://www.example.com/template/rtl/images/topbar/Void.gif
GET /template/rtl/images/topbar/Void.gif HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
Accept: image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.example.com/
Cookie: PHPSESSID=5cdkbo2mr7s5r6qo3ndpcg48e7; mwc=0001202569330.406057.5; BIMvisited=yes
If-Modified-Since: Mon, 21 Jan 2008 21:01:45 GMT
If-None-Match: "db876c-30-44441ccb7c040"
Cache-Control: max-age=0
HTTP/1.x 304 Not Modified
Date: Sat, 09 Feb 2008 14:52:45 GMT
Server: Apache/2.2.4
Connection: close
Etag: "db876c-30-44441ccb7c040"
I'm interested in adding a setting to Cache-Control variable or change server header format so I could somehow tell the browser that GIFs are VALID for 24 hours so he doesn't have to request their headers, just serve them directly from localhost.
My attempts:
1) Modify cache-control
<FilesMatch "\\.(png¦ico¦¦jpg¦jpeg¦png¦gif¦js¦css¦swf)$"> # 30 days
Header set Cache-Control "public,max-age=2592000"
</FilesMatch>
- in theory would make these file types to expire in 30 days
==> the browser still requests for headers of these files.
2) add ExpireByType
ExpiresActive On
ExpiresByType image/gif "access plus 360 days"
ExpiresByType image/png "access plus 360 days"
ExpiresByType image/jpeg "access plus 360 days"
ExpiresByType image/jpg "access plus 360 days"
-> theory says the file will expire in 360 days from access time
-> this modification adds to server's reply:
Expires: Tue, 03 Feb 2009 15:04:03 GMT
Cache-Control: max-age=31104000
==> the browser STILL requests for header of each file.
Does anyone have experience with HTTP headers?
For my knowledge there is a special header format that would tell the browser to to request headers but I don't know what is that.
Kind regards,
Dragos Rusu
[edited by: jdMorgan at 6:50 pm (utc) on Feb. 9, 2008]
[edit reason] No URLs or sigs, please. See Terms of Service. [/edit]
<FilesMatch "\\.(png¦ico¦¦jpg¦jpeg¦png¦gif¦js¦css¦swf)$">
<FilesMatch "\.(png¦ico¦jpe?g¦gif¦js¦css¦swf)$">
Also, for a slight performance improvement, put your image types in order, from most-requested to least-requested (check your server stats to confirm).
Example:
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/css A86400
ExpiresByType text/javascript A86400
ExpiresByType application/x-shockwave-flash A2592000
#
<FilesMatch "\.(gif¦jpe?g¦png¦ico¦css¦js¦swf)$">
Header set Cache-Control "public"
</FilesMatch>
I set the Expires time to one day for CSS and JS MIME-types; The chances that you might need to change your CSS or JS files are much higher than for your image files, and you do not want users to have problems for more than a few hours if they have cached the old CSS and JS files!
Make sure the MIME-types in my ExpiresByType list above agree with those declared by your server!
Replace all broken pipe "¦" characters above with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim
[edited by: jdMorgan at 7:22 pm (utc) on Feb. 9, 2008]
Test it and find out.
Jim
did you mean http HEAD requests [w3.org]?
if so, jim's post applies the HEAD requests as well as GET requests [w3.org].