Forum Moderators: phranque

Message Too Old, No Replies

Adding Expires headers

Adding Expires headers

         

jimmybeige2

8:57 am on May 11, 2010 (gmt 0)

10+ Year Member



Hi,
I am using htaccess to set expires headers for the files in my site to speed up the site. It has worked for most files with one exception. I have gzipped some css and js files using PHP, so they have the a php extension.

eg combined-styles-zip.php, myjs_file_zip.php

I am using the following code in the htaccess file:


<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType text/php "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 text/javascript "access plus 216000 seconds"
ExpiresByType image/swf "access plus 216000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>


Firefox's YSlow is telling me that the gzipped files still do no have expires headers. Is there something wrong with the above code?

Thanks in advance!

jdMorgan

1:26 pm on May 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the MIME-type for the compressed files? Is it listed in your Expires settings above?

I suggest that you set you "media files" to expire in two weeks, things like JS and CSS at eight to 24 hours, and everything else that may need to change quickly to less than that.

The "access plus 1 second" settings might as well be set to zero. If these things really need to be updated on every load, then consider setting the Cache-Control header to "no-store" (using mod_headers directives wrapped in a <FilesMatch> container, for example). Alternatively, consider setting a longer Expires time, and forcing revalidation with

Header set Cache-Control: "no-cache, must-revalidate"

This would allow resources such as your pages to be cached for a much longer period of time, but force the browser to check with the server for updates using an "If-Modified-Since" request header. This will only work if your scripts are cache-aware and can return proper "304-Not Modified" responses for resources which have not been updated since the time in the If-Modified-Since header.

You should also consider enabling and using Etags.

Jim