title: Creating a great .htaccess file that handles shared resources well
body: <p>I am trying to create an ideal .htaccess file that will tick all the boxes for taking advantage of server compression, but only where it makes sense, and caching of resources on public proxies, again where it makes sense. I have been feeling my way through the process and I think I am pretty much there, but I suspect there might be a bit of finessing left to do and I thought I'd invite suggestions. I have my suspicions it's not there yet because of a great tool I have discovered and I have to share that with you to begin with.</p>
  
  <p><a href="http://www.pingdom.com" rel="nofollow">www.pingdom.com</a> has a great suite of website analysis tools, many of which are free to use and personally I think the best is <a href="http://tools.pingdom.com/fpt/" rel="nofollow">http://tools.pingdom.com/fpt/</a>. This shows you the load time of every element of your page, but more importantly, under it's 'Performance Grade' tab it offeres a breakdown of where things could be better. Now I use a number of JQuery resources that are served by Google (and others) and I understand these should exist on many proxy servers. I'm not sure how to say that in my .htaccess file (although I have tried) and sure enough, Pingdom's anaylsis includes the following feedack:</p>
  
  <blockquote>
    <p>The following publicly cacheable, compressible resources should have a
    "Vary: Accept-Encoding" header:</p>
    
    <p>•http://jmar777.googlecode.com/svn/trunk/js/jquery.easing.1.3.js</p>
    
    <p>•http://kwicks.googlecode.com/svn/branches/v1.5.1/Kwicks/jquery.kwicks-1.5.1.pack.js</p>
  </blockquote>
  
  <p>Well I thought I'd done that, but then again, perhaps it's up to the servers that actually serve those resources to set those headers, and maybe there's nothing I can do about it? Is that so? Anyway here is my .htaccess file at the moment. Please note I have the caching set insanely low because I am still just experimenting / learning with it. I will adjust this up before I go live with it.</p>
  
  <pre><code>suPHP_ConfigPath /home/mydomain/public_html
  &lt;Files php.ini&gt;
  order allow,deny
  deny from all
  &lt;/Files&gt;
  
  &lt;ifModule mod_deflate.c&gt;
  &lt;filesMatch "\.(js|css|php|htm|html)$"&gt;
  SetOutputFilter DEFLATE
  &lt;/filesMatch&gt;
  &lt;/ifModule&gt;
  
  # 1 HOUR
  &lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|htm|html|)$"&gt;
  Header set Cache-Control "max-age=3600, public"
  &lt;/filesMatch&gt;
  
  # PHP - NO CACHING WANTED DUE TO USING SESSION COOKIES
  &lt;filesMatch "\.(php)$"&gt;
  Header set Cache-Control "private"
  &lt;/filesMatch&gt;
  
  # STORE BOTH COMPRESSED AND UNCOMPRESSED FILES FOR JS &amp; CSS
  &lt;IfModule mod_headers.c&gt;
    &lt;FilesMatch "\.(js|css|xml|gz)$"&gt;
      Header append Vary Accept-Encoding
    &lt;/FilesMatch&gt;
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>You can see I am trying to do a 'Vary Accept-Encoding' towards the end of the file but not sure if this is what's needed. How do I tell clients to access JQuery and the like the proxies those files are undoubtedly stored at, and is there anything else I can do to make my .htaccess file deliver faster and my search engine friendly content? </p>
  
  <p>Thank you for your thoughts.</p>
  
  <p><em>Edit:</em></p>
  
  <p>It seems my questions here were not clear enough so here goes with some clarification:</p>
  
  <p>1) Is the JQuery library, hosted at Google, something whose proxy availability is somehow under the control of my .htaccess settings, because I make remote reference to it in my PHP, and if so, how should I say, in my .htaccess file, 'please cache that library in a proxy for a year or so'? </p>
  
  <p>2) How too should I specify that Google hosted files should be provided compressed and uncompressed via 'Vary Accept-Encoding'? At a guess I'd say both issues were under Googles control and not mine, so to make that absolutely explicit...</p>
  
  <p>3) Is the compression choices and proxification of files like the JQuery library under my control or under (in this case) Googles? </p>
  
  <p>4) Generally, is anything in my .htaccess file expressed in a sub-optimal (long winded) way and how could I shorten/compact it? </p>
  
  <p>5) Is anything in the .htaccess file sequenced in a way that might cause problems - for example I refer to CSS under three separate rules - does the order matter? </p>
  
  <p><em>(End of Edit).</em></p>