Hi all,
I’m trying to please YSlow so it stops giving me all A’s and five F’s. One of the F’s concerns adding expiry headers. Now, I already have code like the below (for various mime types) in my. htaccess and YSlow seems to like that, nonetheless this doesn’t work for js/images loaded from external domains (i.e. banners).
# Media files - 7 days
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "max-age=302400, must-revalidate, public, no-transform"
</FilesMatch>
I’ve tried to get my head round this and it appears ExpiresDefault is the fix? I’m confused how ExpiresDefault works given that Header set Cache-Control is supposed to be doing the same thing?
Or maybe Header set Cache-Control is fine providing the expirary date it set to at least 48 hours?
Thanks,
Okay, so I’ve come up with the below in my .htaccess.
This is what YSlow states:
Add Expires Headers - Grade F - YSlow no longer says anything about there not being expires headers set for page components (images, js etc.) pulled from my server with the exception of the minify script. It does however insist externally loaded components (mostly js’s) don’t have a valid expires date set. Most of these do have one but their date it set to 1997/1998. Most are banners. Nothing I can do about them is there? Also, why doesn’t this grade go down to C instead of staying at a F?
Configure enetity tags (Etags) - Grade F - YSlow still insists all the png/jpg/ico files pulled from my server don’t have a valid etags setup.
I’ve looked at about 40-50 pages online and it would appear I’m not doing anything inherently wrong except YSlow seems to differ in opinion. Each time I modify the .htaccess file I upload it online and test the online version of the site.
Anyone fluent in Apache talk no what’s going haywire? Thanks.
# Do not generate expiration header performance tweak
Header unset ETag
FileETag None
#Enable Expires
ExpiresActive On
# Mime expires
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 text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
# Media files - 7 days
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "max-age=302400, must-revalidate, public, no-transform"
</FilesMatch>
# HTML etc. files - 2 hours
<FilesMatch "\\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate, public, no-transform"
</FilesMatch>
# JS/CSS files - 2 days
<FilesMatch "\\.(js|css)$">
Header set Cache-Control "max-age=86400, must-revalidate, public, no-transform"
</FilesMatch>
# PHP etc. dynamic files - disabled
<FilesMatch "\\.(pl|php|[sf]?cgi|spl)$">
Header set Cache-Control: "max-age=0, no-store"
</FilesMatch>
Below is my latest effort. With this I can get YSlow’s etags score down to a C grade (down from F above). It would be an A if it wasn’t for an odd peculiarity with two external images (outside my host). These images still get a telling off for whatever reason. What’s more puzzling is that I use random banner ads which also have jpeg/gif images and their etags pass okay. Confusing or what?
Speaking of external banners which use also use images, I still can’t get YSlow to upgrade my expires heading rating up from F. It’s usually banner images from AWin1 that are the culprits but Google’s Analytics JS also gets blamed followed my by favicon and hosted minify script.
# Set Entity Tag header
FileETag MTime Size
# Add P3P Privacy Header
Header set P3P "policyref=\\"/w3c/p3p.xml\\""
#Enable Expires and reset to zero
ExpiresActive On
ExpiresDefault A0
# Configure mime expires
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/ico "access plus 2592000 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 application/x-javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
# Media files
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>
# HTML etc. files
<FilesMatch "\\.(html|htm|xml|txt|xsl)$">
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>
# JS/CSS files
<FilesMatch "\\.(js|css)$">
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>
# PHP etc. dynamic files - disabled
<FilesMatch "\\.(pl|php|[sf]?cgi|spl)$">
Header set Cache-Control: "max-age=0, no-store"
</FilesMatch>