2

I am trying to optimize a Drupal 7 site. I noticed the Expires header is set to just 6 hours, although according to my .htaccess file, it should be 2 weeks. Then i found out mod_expires module is not enabled. Now i have two questions:

  1. Since i don't have the necessary rights, is there a way to set the Expires header without enabling mod_expires?
  2. What is setting the header to 6 hours?

EDIT: Another strange thing is that the header is not there at all for some of the css files.

Also the settings in my /admin/config/development/performance is as follows, if related to this:

Cache pages for anonymous users: checked Cache blocks: checked Minimum cache lifetime: none Expiration of cached pages: 1 day

7
  • /admin/config/development/performance?
    – Clive
    Apr 3 '14 at 12:10
  • $conf['page_cache_maximum_age'] = ... in settings.php maybe?
    – Clive
    Apr 3 '14 at 12:35
  • That value is not set
    – lunr
    Apr 3 '14 at 15:07
  • What do you want to have 2 week expires? Just files like images and css/js?
    – mikeytown2
    Apr 3 '14 at 15:32
  • Yes. For the static files.
    – lunr
    Apr 3 '14 at 15:39
1

Here is some boilerplate Apache rules I came up with for this question based off of the rules found in the advagg readme. The inverted files match is untested but based off this post: https://stackoverflow.com/questions/12926604/inverted-filesmatch; got what needed to be excluded by looking at core's .htaccess

<FilesMatch "(?<!\.php)$">
  # No mod_headers
  <IfModule !mod_headers.c>
    # No mod_expires
    <IfModule !mod_expires.c>
      # Use ETags.
      FileETag MTime Size
    </IfModule>
  </IfModule>

  # Use Expires Directive.
  <IfModule mod_expires.c>
    # Do not use ETags.
    FileETag None
    # Enable expirations.
    ExpiresActive On
    # Cache all files for 2 weeks after access (A).
    ExpiresDefault A1209600
  </IfModule>

  <IfModule mod_headers.c>
    # Do not use etags for cache validation.
    Header unset ETag
    <IfModule !mod_expires.c>
      # Set a Cache-Control header to 2 weeks.
      Header set Cache-Control "max-age=1209600, no-transform, public"
    </IfModule>
    <IfModule mod_expires.c>
      Header append Cache-Control "no-transform, public"
    </IfModule>
  </IfModule>
</FilesMatch>

In your case the best you can do is to use ETags.

Note: If you happen to be serving all you static file assets from a CDN then you could enable far-future headers in the CDN module. Doing it this way will route almost all static file traffic through PHP (on a origin request) so it can be extremely damaging to the sites performance if you are not using a CDN.

4
  • Thanks for the answer, but "ETag" headers are currently set actually. But that "Expires" header is annoying and Google Page Insight is complaining about it.
    – lunr
    Apr 3 '14 at 17:49
  • You are out of luck if you can not get mod_headers or mod_expires enabled on apache :(
    – mikeytown2
    Apr 3 '14 at 18:24
  • Ok, thx. Do you have any idea what may be setting it to 6 hours?
    – lunr
    Apr 4 '14 at 5:07
  • Something up stream or Apache. Good luck
    – mikeytown2
    Apr 5 '14 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.