1

my php-generated thumbnail files and combined javascript and css files (all having their expiration dates anc cache=public set etc) return the full content sometimes, other times they load from proxy cache!

This is the comment that redbot.org gives, sometimes:

An If-Modified-Since conditional request returned the full content unchanged.

*HTTP allows clients to make conditional requests to see if a copy that they hold is still valid. Since this response has a Last-Modified header, clients should be able to use an If-Modified-Since request header for validation. RED has done this and found that the resource sends a full response even though it hadn't changed, indicating that it doesn't support Last-Modified validation.**


the PHP thumbnail generator header

header ("Content-type: image/jpeg");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 404800000)." GMT");
header ("Expires: " . gmdate("D, d M Y H:i:s", time() + 2419200) . " GMT");
header ("Cache-Control: public, max-age=2419200");

htaccess

<IfModule mod_headers.c>
ExpiresActive On
ExpiresDefault M172800

##### DEFAULT EXPIRES
<FilesMatch "\\.(ico|jpg|png|gif|svg|swf|css|js|fon|xml|pdf|flv)$">
    ExpiresDefault M1209600
    Header set Cache-Control "max-age=1209600, public"
</FilesMatch>

##### DYNAMIC PAGES
<FilesMatch "\\.(php|cgi|pl)$">
    ExpiresDefault M7200
    Header set Cache-Control "public, max-age=7200"
</FilesMatch>

Header unset Pragma
Header unset ETag
Header unset Last-Modified
FileETag None
</IfModule>

Update: New Info:

google SpeedTest gives 91/100 score on the top it says: and list all the files except the php generated files that have a explicit expire header set ((which still return full content!??) it says:

The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources.

2 Answers 2

1

Can you use Firebug and paste the HTTP response headers. I have a feeling that even though in your code you are setting cache control to Public, Apache is overriding that because for Php File type you are setting Cache-Control to private.

One thing you can do it remove the cache settings for Dynamic Pages from Apache configuration. That should fix the problem because a Proxy doesn't cache a response without the correct headers.

EDIT

Hi Sam, Revisiting you question I found the solution to the problem. The following code snippet appears to be a problem. In the output of your Php the Last-Modified header always changes and when a browser sends a 304 If modified request it see a change and therefore re-requests that content.

header ("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 404800000)." GMT");

Unset Last-Modified and ETags from your content to speed up the website. This site provides some excellent tips too.
http://www.askapache.com/htaccess/apache-speed-last-modified.html

2
  • hmmm i seee very interesting comments Sammeer! I think i have a firebug in my firefox, will check there and search them http headers and get back here within half a day. cheers, Sam
    – Sam
    Dec 15, 2010 at 5:28
  • Dear Sameer, i updated the question and my htaccess. But even with php set to "public" isntead of "private" still there is caching problem. sometimes they show up as good, other times the return the full content. PS i cand find http headers in Firebug, is that a plugin for Firebug?
    – Sam
    Dec 15, 2010 at 12:55
0

I added the following code in my htaccess file when http://pagespeed.googlelabs.com/ in chrome I got Leverage browser caching which is now solved but now it gives error of Specify a cache validator, how to do it else I have already added cache controls, below is the code

<"ifModule mod_gzip.c>

  mod_gzip_on Yes

  mod_gzip_dechunk Yes

  mod_gzip_item_include file \\.(html?|txt|css|js|php|pl)$

  mod_gzip_item_include handler ^cgi-script$

  mod_gzip_item_include mime ^text/.*

  mod_gzip_item_include mime ^application/x-javascript.*

  mod_gzip_item_exclude mime ^image/.*

  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

<"/ifModule>

<"ifModule mod_expires.c>

  ExpiresActive On

  ExpiresDefault "access plus 1 seconds"

  ExpiresByType text/html "access plus 1 seconds"

  ExpiresByType image/gif "access plus 2592000 seconds"

  ExpiresByType image/jpeg "access plus 2592000 seconds"

  ExpiresByType image/png "access plus 2592000 seconds"

  ExpiresByType text/css "access plus 604800 seconds"

  ExpiresByType application/x-javascript "access plus 216000 seconds"

<"/ifModule>

<"ifModule mod_headers.c>

  <"filesMatch "\\\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">

    Header set Cache-Control "max-age=2592000, public"

  <"/filesMatch>

  <"filesMatch "\\\\.(css)$">

    Header set Cache-Control "max-age=604800, public"
  <"/filesMatch>
  <"filesMatch "\\\\.(js)$">

    Header set Cache-Control "max-age=216000, private"

  <"/filesMatch>

  <"filesMatch "\\\\.(xml|txt)$">

    Header set Cache-Control "max-age=216000, public, must-revalidate"

  <"/filesMatch>

  <"filesMatch "\\\\.(html|htm|php)$">

    Header set Cache-Control "max-age=1, private, must-revalidate"

  <"/filesMatch>

<"/ifModule>

<"ifModule mod_headers.c>

  Header unset ETag

<"/ifModule>

FileETag None

<"ifModule mod_headers.c>

  Header unset Last-Modified

<"/ifModule>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .