Jump to:

23481 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Having trouble setting expires headers and so on...

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 301 Views
  • Spaghetti
    Community Member
    31 Posts

    Having trouble setting expires headers and so on... Link to this post

    I've been trying to speed up my site and various speed measuring sites have pointed out that my main priority should be to set the expires header on the served content to 'Leverage browser caching'. I thought I could do this by making use of mod_expires, but for some reason it's not working.

    Also I've been advised to add 'Header append Vary: Accept-Encoding', because apparently some clients can't handle decryption (fair enough....?!). So I looked at adding that via mod_headers.

    Both of those Apache modules are installed on my VPS but after testing with those page speed tools and double-checking the headers with a tool called rebot, http://redbot.org/, I can see it's not working.

    What am I doing wrong?

    Here's the htaccess script:

    <Files *.ss>
       Order deny,allow
       Deny from all
       Allow from

    <Files web.config>
       Order deny,allow
       Deny from all

    # This denies access to all yml files, since developers might include sensitive
    # information in them. See the docs for work-arounds to serve some yaml files
    <Files *.yml>
       Order allow,deny
       Deny from all

    # Define some expiry header settings.
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/html "access plus 5 minutes"
    ExpiresByType image/gif "access plus 7 day"
    ExpiresByType image/png "access plus 7 day"
    ExpiresByType image/jpg "access plus 7 day"
    ExpiresByType image/jpeg "access plus 7 day"
    ExpiresByType image/ico "access plus 7 day"
    ExpiresByType text/css "access plus 7 day"
    ExpiresByType text/javascript "access plus 7 day"
    ExpiresByType application/x-javascript "access plus 7 day"

    # Append the 'Vary: Accept-Encoding' for resources that might need it.
    <IfModule mod_headers.c>
    <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding

    ErrorDocument 404 /assets/error-404.html
    ErrorDocument 500 /assets/error-500.html

    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase '/'

       RewriteRule ^vendor(/|$) - [F,L,NC]
       RewriteRule silverstripe-cache(/|$) - [F,L,NC]
       RewriteRule composer\.(json|lock) - [F,L,NC]
       RewriteCond %{REQUEST_URI} ^(.*)$
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_URI} !\.php$
       RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]

    and here's the output from redbot:

    HTTP/1.1 200 OK
    Server: nginx
    Date: Thu, 09 Jan 2014 12:35:02 GMT
    Content-Type: text/html; charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Cache-Control: no-cache, max-age=0, must-revalidate, no-transform, max-
    Expires: Thu, 09 Jan 2014 12:40:02 GMT
    Content-Encoding: gzip

    It also says 'This response is negotiated, but doesn't have an appropriate Vary header.' and critically: 'The max-age Cache-Control directive appears more than once.' - is something else inside Silverstripe or anything else setting that expiry time to 0?

    tl;dr; Do I have to do anything special in SilverStripe to set an expiry time on files and/or content?

    Any help, much appreciated.

  • Spaghetti
    Community Member
    31 Posts

    Re: Having trouble setting expires headers and so on... Link to this post

    I've just read the documentation here: http://doc.silverstripe.org/framework/en/howto/cache-control

    removed my header manipulation code from the .htaccess file and rechecked using Redbot to see what the default headers are - since I've not touched the site all weekend, I'd expect at the very least for the expires header to be '+2 days' - it isn't, it's 0.

    Is this a bug or am I missing something?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.