Hello,

This is a super cool way to implement client side caching of files in the browser with apache mod expiry:

http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html

Thought it may be a good idea to add these to boost as an option :)

Comments

giorgio79’s picture

Title: Enabling client side caching with mod_expiry? » Enabling client side caching with mod_expires
giorgio79’s picture

It seems this even existed in Drupal 4 htaccess but somewhere it was removed:
#40597: drupal caching too aggressive by default

mikeytown2’s picture

Issue with this is logging in and out of the site. I did some experimental work with this in terms of the "Turn off clean url's for logged in users" setting.

giorgio79’s picture

For images and js this may still be good :)

Perhaps you cached the html for the logged in user and on logout it was still showing?

giorgio79’s picture

Title: Enabling client side caching with mod_expires » Enabling client side caching with mod_expires or mod_headers

I notice in the second of the two methods, now with mod headers, there is an example like this, where dynamic files are not cached on the client, this might solve it:

# Turn on Expires and set default expires to 3 days
ExpiresActive On
ExpiresDefault A259200
 
# Set up caching on media files for 1 month
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
  ExpiresDefault A2419200
  Header append Cache-Control "public"
</FilesMatch>
 
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
  ExpiresDefault A7200
  Header append Cache-Control "private, must-revalidate"
</FilesMatch>
 
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
  ExpiresDefault A0
  Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
  Header set Pragma "no-cache"
</FilesMatch>

If we can get this to work, it will be a massive selling point for Boost / Drupal. As per AskApache:

By setting an expiry time for the files on your Web site, you can go even farther than merely relying on the conditional GET and the 304 response that a server sends when a file has not changed… You can prevent the contact with the server from happening at all by using the Expires header and the Cache-control header.
kentr’s picture

Perhaps old news...

Seems to me this is already somewhat possible:

For CSS / JS, if you enable Optimize CSS files & Optimize JS files (maybe only available in Pressflow?), the aggregated files are stored by default in the Drupal files directory, where you can set the Cache-Control / Expires headers as desired.

Same with images & media files -- you can already control the headers in the main .htaccess file, subdirectory .htaccess files, etc.

For me, the only thing that's missing are the static versions of dynamic content under the Boost cache directory. I would definitely prefer that Boost not write the .htaccess to disable all caching.

Issue with this is logging in and out of the site. I did some experimental work with this in terms of the "Turn off clean url's for logged in users" setting.

I gather that issue is fixed by these lines in .htaccess:

  # Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request
  RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]
  RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add|comment/reply))|(/(edit|user|user/(login|password|register))$) [OR]
  RewriteCond %{HTTPS} on [OR]
  RewriteCond %{HTTP_COOKIE} DRUPAL_UID