1

Quick question. I'm trying to enable browser caching for a wordpress site on Apache with SSL enabled. I installed mod_expires with sudo a2enmod expires (I verified it's enabled and listed on /etc/apache2/mods-enabled) I edited the .htaccess file as suggested by GTMetrix

My .htaccess (which I verified it's being accessed by uncommenting the rewrite rules and seeing pages going offline) is as follows:

# BEGIN WordPress
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Browser Caching Start #
<IfModule mod_expires.c>
        # Enable expirations
        ExpiresActive On
        # Default directive
        ExpiresDefault "access plus 1 month"
        # My favicon
        ExpiresByType image/x-icon "access plus 1 year"
        # Images
        ExpiresByType image/gif "access plus 1 month"
        ExpiresByType image/png "access plus 1 month"
        ExpiresByType image/jpg "access plus 1 month"
        ExpiresByType image/jpeg "access plus 1 month"
        # CSS
        ExpiresByType text/css "access plus 1 month"
        # Javascript
        ExpiresByType application/javascript "access plus 1 year"
</IfModule>
# Browser Caching End #

Restarted apache and tested on Google and GTMetrix. I keep getting "leverage browser caching" showing the images expiring in 4 hours.

https.../image.png (4 hours)

Any suggestions as to how to debug this, or are you seeing something I am doing wrong?

Here is the http response header for one of the images:

Content-Length: 13937
Connection: keep-alive
Set-Cookie: __cfduid=dc6febbc08cc78186b2444352064d20611481224874; expires=Fri, 08-Dec-17 19:21:14 GMT; path=/; domain=.mydomain.com; HttpOnly
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Last-Modified: Wed, 07 Dec 2016 05:20:33 GMT
ETag: "3671-5430aae243b0e"
Cache-Control: public, max-age=2592000
Expires: Sat, 07 Jan 2017 19:21:14 GMT
X-Content-Type-Options: nosniff
CF-Cache-Status: MISS
Accept-Ranges: bytes
Server: cloudflare-nginx
CF-RAY: 30e294493e2f3fd7-YUL

I see "Expires: Sat, 07 Jan" so it SHOULD be a month, but Google keeps writing it's 4 hours? What's going on here? :)

Ben
  • 111
  • 3
  • What are the HTTP response headers for these PNG files? (Add these to your question.) Presumably this is unrelated to [your other question](http://serverfault.com/questions/818892/cloudflare-ssl-full-nginx-puma-rails) regarding CloudFlare? – MrWhite Dec 08 '16 at 19:18
  • @w3dk, I'm not sure if it's related. I edited the question and added the info you requested. – Ben Dec 08 '16 at 19:25
  • The `max-age` directive of the `Cache-Control` header will take priority over the `Expires` header in modern browsers - but this is also 30 days (1 month), so not sure. Cookies can also break the cache - but the "4 hour" figure doesn't seem to apply to the headers shown above? Doesn't CloudFlare have it's own cache-settings? – MrWhite Dec 08 '16 at 19:41
  • Thank you @w3dk for mentioning cloudflare. They were applying their own cache on top of mine and it was set to 4 hours by default. – Ben Dec 08 '16 at 19:40
  • But why was this "4 hours" not evident in the HTTP response headers you added to the question? – MrWhite Dec 08 '16 at 19:54
  • Why would I know that? I do know that it was cloudflare that was overriding things with their settings because once I changed it, it worked. – Ben Dec 08 '16 at 20:20
  • Well, the headers you added to the question can't be the same headers that the Google/GTMetrix tools were seeing? So, the request would seem to be different in some way? – MrWhite Dec 08 '16 at 20:37

0 Answers0