I've got drupal 5.7 living on a windows 2003 server running apache 2.0, php 5.1.2 and mysql 5.0. I am using the private files setting (files directory above root) and I have drupal normal cache enabled.
My problem is that drupal never seems to cache any of my images saved above root. I have it set to cache images in my .htaccess file and I have mod_deflate, mod_expires adn mod_headers enabled in apache, I've researched and applied recommendations for optimizing drupal but still, my gifs, jpgs and pngs are not being cached, even though I've indicated in my .htaccess file that I want them cached.
YSlow shows this for images on my front page:
These components do not have a far future Expires header:
(11/19/1978) http://dev.domain.org/system/files/admin/pconnectAd.gif
(11/19/1978) http://dev.domain.org/system/files/admin/schoolStartAd.gif
(11/19/1978) http://dev.domain.org/system/files/admin/qlinks_icons2.gif
Header for qlinks_icons2.gif:
Response Headers
Date: Wed, 18 Jun 2008 14:08:47 GMTServer: Apache
Set-Cookie: SESS604546ee5ef82dd239a01f453b15fcbc=9c5he3gbc1f8n3l32dl87865u5;expires=Fri, 11 Jul 2008 17:42:07 GMT; path=/; domain=.dev.domain.org
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Wed, 18 Jun 2008 14:08:47 GMT
Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0
Keep-Alive: timeout=2, max=73
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/gif
Yet a cssimage saved within root directory is cached:
cssimage http://dev.domain.org/themes/mar/img/banner2.jpg 6/15/2018
Response Headers
Date: Wed, 18 Jun 2008 16:41:37 GMT
Server: Apache
Last-Modified: Wed, 12 Mar 2008 16:21:23 GMT
Etag: "4f06-a8e8-d3f9887c"
Accept-Ranges: bytes
Content-Length: 43240
Cache-Control: max-age=1209600
Expires: Sat, 16 Jun 2018 16:41:37 GMT
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: image/jpeg
I noticed there's a difference with cache-control but I don't understand why the image stored above root is different.
I've put this in my .htaccess file:
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
ExpiresDefault "access plus 2 years"
# Do not cache dynamically generated pages.
ExpiresByType text/html A1
# Set up 10 year caching on commonly updated files
<FilesMatch "\.(xml|js|css)$">
ExpiresDefault "access plus 10 years"
</FilesMatch>
# Set up 10 year caching on commonly updated files
<FilesMatch "\.(gif|jpg|png)$">
ExpiresDefault "access plus 10 years"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php)$">
ExpiresActive Off
</FilesMatch>
# Cache various files for 2 weeks
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf|txt|html|htm)$">
Header set Cache-Control "max-age=1209600"
</FilesMatch>
</IfModule>
It took 36.767s to load my front page according to Yslow which I think is primarily due to the fact that it has to keep regenerating my images because they aren't being cached. One thing I notice is that my css, js files and most of the images in the theme and drupal directories (all in site root) are cached but images that are located above the root don't seem to be.
Thanks in advance for any suggestions/recommendations.
*****Edited June 3, 2010 ******
Seemed only solution was to switch to the public file system which is what I did and now my flash, gifs, jpgs are being saved to browser cache which has tremendously helped with the loading times of my pages.
Recommend setting up a development/mirror site and switching to public there first to iron out the kinks before you do it on a production server. You should also have access to PhpMyAdmin which helps out so you can replace the old private file paths (system/files) with the new public paths (sites/default/files). Using this sql code in PMA was a great help:
UPDATE tablename SET tablefield = replace(tablefield, "findstring", "replacestring");
Good luck.
Comments
private image files are gzipped - shouldn't be
especially since they shouldn't be as defined in the .htaccess file.
I believe this means my gif, jpg and png files shouldn't be gzipped however they are according to Yslow.
image http://dev.domain.org/system/files/admin/qlinks_icons2.gif 11/19/1978 gzip
And again they are automatically set to expire back in 1978. Why isn't drupal caching these files and why does it gzip them? This has me stumped.
Moved images to root and now they are cached
Well, I figured a quick (not extremely efficient) way to make sure un-changing images are cached. This was based on a number of different settings I tried which all pointed to the fact that drupal will not cache image files if they are saved in the private files setting.
I found this out by moving the images from above root (/system/file.gif) to the root of my install and now they are cacheing. Now I'm wondering if the fact that I'm using open_basedir restrictions but the files directory is within the open_basedir setting.
Is this by design that drupal won't cache files if they are set up to be served from drupal above the root? If so, is there a way around this?
So, are private files meant to be cached?
I haven't had a response here and I'm still wondering if the private file setting means none of the images above root will be cached? Any way to cache them?
Same issues in my install.
I have the same issues in my install (drupal 6.10, Apache 2, php 5).
Tried the follow in the httpd.conf, filter for only text/... and explicitly deny images, but everything (including .gif, .jpeg and .png) gets gzipped.
So I disabled the http compression for now.
I would love to know what causes this and how to fix it.
Same issue here
I was thinking that it was problem with imagecache. Can anyone help ?
Drupal Scavenger
It's in the Alias
I was experiencing the same problem. I tried adjusting the lower level .htaccess files with no success and was completely dumbfounded until I looked at the direct path of the image in Firebug's NET tab.
The image path was
http://www.domain.com/images/testimonial.gifWhen I checked that directory, sure enough, there was no file there with that name. I finally realized that "images/testimonial.gif" was not a path to a file, but the URL alias entered in the image node by our production team. The HTML code used in the page node body to access the image referenced the URL alias, not the actual image location which resides in the files directory.Accessing the file directly at "/files/images/testimonial.gif" allowed apache to cache it.
I hope this helps, if you haven't already solved this riddle.
Chris Albrecht
--------
Chris (KeyboardCowboy) - @ChrisAlbrecht
public or private files?
Are you set up with public file system or private? Is the alias due to pathauto?
So, since private files are aliases since there is no "system" directory in the root how can this be set so that apache finds the "system" folder? Did you have to create a rewrite in your htaccess directory?
private directory still prevents image cacheing
I am still experiencing this nightmare - I have a front page filled with images and a couple swf files which load every single time you visit the page. They are not cached which results in very long display times and visitors who eventually give up in frustration. I still have not found a solution to this problem other than switching to the public file directory system which I wish had been recommended in the first place.
This has been a bear of a situation to defend when folks ask me why I'm using drupal (drupal 5 at the moment due to modules not upgraded and too much invested in current site.
*groan*