Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make Google PageSpeed happy, but my .htaccess skills are limited. I'm particularly struggling with browser and proxy caching. Does anyone have a template I can use?

Here's what I have for compression so far:

# JavaScript MIME type issues:
#   1. Apache uses "application/javascript":
#   2. IIS uses "application/x-javascript":
#   3. SVG specification says it is text/ecmascript:
#   4. HTML specification says it is text/javascript:
#   5. "text/ecmascript" and "text/javascript" are considered obsolete:

# Compression:
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml

    # The following MIME types are in the process of registration
    AddOutputFilterByType DEFLATE application/xslt+xml
    AddOutputFilterByType DEFLATE image/svg+xml

    # The following MIME types are NOT registered
    AddOutputFilterByType DEFLATE application/mathml+xml
    AddOutputFilterByType DEFLATE application/rss+xml

    # Compress JavaScript; make sure to list all possible MIME types for JavaScript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE text/ecmascript
    AddOutputFilterByType DEFLATE text/javascript
share|improve this question

Here's a template you can use. I got it from someone, don't know who the original author is but it could very well be output of yslow plugin (

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

# if you don't use filenames to version, lower the css and js to something like
#   "access plus 1 week" or so

<IfModule mod_expires.c>
  Header set cache-control: public
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

# cache.manifest needs re-reqeusts in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"

# your document html 
  ExpiresByType text/html                  "access"

# rss feed
  ExpiresByType application/rss+xml       "access plus 1 hour"

# favicon (cannot be renamed)
  ExpiresByType image/  "access plus 1 week" 

# favicon (cannot be renamed)
  ExpiresByType image/  "access plus 1 week" 

# media: images, video, audio
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType video/ogg                 "access plus 1 month"
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType video/mp4                 "access plus 1 month"

# webfonts
  ExpiresByType font/ttf                  "access plus 1 month"
  ExpiresByType font/woff                 "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"

# css and javascript
  ExpiresByType text/css                  "access plus 1 month"
  ExpiresByType application/javascript    "access plus 1 month"
  ExpiresByType text/javascript           "access plus 1 month"

# Since we're sending far-future expires, we don't need ETags for
# static content.
FileETag None

# use utf-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8
# force utf-8 for a number of file formats
AddCharset utf-8 .html .css .js .xml .json .rss
share|improve this answer

Your syntax looks okay. Some folks might call me old fashioned for doing so, but I use apache's sample configuration shown here:

Also, I highly recommend putting these rules in your apache configuration files rather than in .htaccess files. This is because when a request comes in, apache has to hunt around for your .htaccess files, read them, and process their configurations on the fly. If you put the configuration in your main apache configuration files instead, it compiles them when apache is first started.

On very busy sites with large amounts of requests per second, using .htaccess files can drag down the speed of your site pretty quickly.

share|improve this answer
thanks for the insight. My main problem deals with caching, though; the snippet I gave was just for compression. Any ideas about browser & proxy caching that will make PageSpeed happy? – user57386 Oct 17 '10 at 20:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.