Only apply "do not cache" headers to files inside the the cache folder.

firebus - October 20, 2007 - 07:12
Project:Boost
Version:5.x-1.x-dev
Component:Apache integration
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

with boost enabled, firefox never caches any images, css, etc. presumably this is the case for any browser that respects the cache-control headers.

i'll try and submit a patch for the apache htaccess changes...

#1

firebus - October 20, 2007 - 19:39

huh. it looks like and it's ilk are not allowed in .htaccess files.

so the solution is to have a separate .htaccess file in the cache directory

i took the following out of the main .htaccess and added it to a new .htaccess in cache:

  <IfModule mod_headers.c>
      Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
      Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  </IfModule>

#2

bangpound - October 26, 2007 - 10:30

I just noticed this today because I checked out my sites headers, and it's troubling that Boost sacrifices client caching for server caching. FWIW, I've installed your patch and my initial observation is that it works well.

#3

Mojah - October 31, 2007 - 09:44
Priority:normal» critical

Hi,

status changed to critical.

Thanks for pointing this out. We have Boost installed on a multi-site production server and our root .htaccess was edited according to the boost .htaccess rules which was probably affecting all our sites.

The changes work perfectly and the module is running smoothly.

To confirm for other boost users...edit your main .htaccess file in root and remove the following lines

  <IfModule mod_headers.c>
      Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
      Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  </IfModule>

Create a new .htaccess file and paste the above lines into it. Upload this file to your cache directory.

To see it working, delete some of your old cached files (which will show small file sizes of around 20 bytes before this change) and then call them with a browser as an anonymous user. You will notice the new file created with boost will be much larger in size (now in kB).

Excellent module!

#4

Mojah - October 31, 2007 - 12:15

There is some incorrect information in my last post. It appears that images are not being cached. I notice when visiting the site using ie that the browser continues to request image files on each page load.

The notes about checking file sizes to see if files are being cached may not be true as I notice that boost is creating symbolic links for nodes (in the nodes folder cache/domain.org/0/node). So to see if static files are being created follow the symbolic link.

This bug/by design issue is related only to css/image/js files as the title says and not the actual content as I misunderstood.

#5

firebus - November 3, 2007 - 06:41

drupal, by default, doesn't cache text/html type files

                  # Do not cache dynamically generated pages.
                  ExpiresByType text/html A1

which should apply to boost's cache files as well, unless i'm missing something. can anyone explain why boost bothers with setting separate caching in the first place? i suspect this is a carryover from the 4.x version...

#6

Christefano - January 13, 2008 - 17:31

I've seen this problem, too. Thank you, firebus, for posting a solution.

#7

bluehut - January 21, 2008 - 20:09

I can't explain why boost does this, but on the site I'm using it I've just removed the lines you suggested (i.e. without moving them to the cache directory) and the site now meets my caching requirements perfectly as far as I can tell.

#8

EvanDonovan - February 25, 2009 - 21:18
Status:active» needs review

Should this be committed to the module? Seems like a good idea....

#9

ckng - March 2, 2009 - 07:35

#3 & #5 works for me, now all are loaded from browser cache if available.

#10

mikeytown2 - October 29, 2009 - 23:12
Version:5.x-1.0» 6.x-1.x-dev

I add these line to the bottom of my .htaccess file and it seems to work.

#Cache These Files Forever - gif|png is a little aggressive, i know.
<FilesMatch "\.(ico|js|css|js.gz|css.gz|gif|png)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>

# 2 HOURS - Not sure how well this one works
<FilesMatch "\.(jpg|JPG|jpeg|xml|txt|flv|swf)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

Although I should probably re-do some of the above once I read
http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html
Anyway the reason for boosts Cache-Control settings is for users who log-in and log-out.

#11

mikeytown2 - May 24, 2009 - 09:08
Title:boost cache headers apply to css, js, image files, etc. they should only apply to .html files, or only to the cache folder....» Only apply "do not cache" headers to files inside the the cache folder.
Category:bug report» feature request
Priority:critical» normal

Will look into using this method
http://httpd.apache.org/docs/trunk/mod/core.html#directory

untested

<Directory /cache>
  <FilesMatch "\.(html.gz|html)$">
    <IfModule mod_headers.c>
        Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
        Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
    </IfModule>
  </FilesMatch>
</Directory>

#12

Alexander Ufimtsev - May 25, 2009 - 14:03

"Header set" should be used instead of "Header add", otherwise Apache sends TWO values in Expires and Cache-Control.
Directory tag is not going to work in .htaccess - it should be placed in Apache config directly or the content of this should be added in .htaccess in cache/

#13

mikeytown2 - May 26, 2009 - 19:57

Partial commit, adding .htaccess to cache dir not done yet.

#14

mikeytown2 - June 5, 2009 - 08:35
Status:needs review» postponed (maintainer needs more info)

Not sure splitting the htaccess file up is the smartest thing to do; seems like it would add too much complexity. If there is a good argument for doing it, please state your case.

#15

sidharth_k - June 10, 2009 - 22:45

#16

mikeytown2 - June 10, 2009 - 23:07

@sidharth_k
"Header set" is already in 6.x-1.x-beta1

The question has to do with mutiple .htaccess files. Is this a vote for that?
http://groups.drupal.org/node/22864
In short every single .htaccess has to potential to slows down apache; with the already included FilesMatch directive it should only apply to *.html & *.html.gz files so it's sorta overkill, thats why I'm asking if this is really needed.

#17

mikeytown2 - June 18, 2009 - 10:08
Status:postponed (maintainer needs more info)» won't fix

marking wont fix, as <FilesMatch "\.(html.gz|html)$"> is in place. multiple .htaccess files would make this module even more complex.

#18

mikeytown2 - July 13, 2009 - 10:45

#19

mikeytown2 - October 7, 2009 - 02:56
Version:6.x-1.x-dev» 5.x-1.x-dev
Status:won't fix» needs review

moving this back to 5.x

#20

mikeytown2 - February 6, 2010 - 19:00
Status:needs review» closed

Closing all 5.x issues; will only reevaluate if someone steps up #454652: Looking for a co-maintainer - 5.x

Reason is 6.x has 10x as many users as 5.x; also last 5.x dev was over a year ago. The 5.x issue queue needs to go.

 
 

Drupal is a registered trademark of Dries Buytaert.