1

I'm trying to leverage the browser cache for my Drupal 8 site. I saw many posts regarding it, but whenever I edit the .htaccess file, there is still no difference in testing. This is my code right now.

 # Requires mod_expires to be enabled.
 <IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On

 # Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600

<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
  </FilesMatch>
    </IfModule>

I read Leverage browser caching issue, but I still don't get it to work.

I am using Apache 2.4.

httpd -M | grep expire 
[Thu Jan 11 15:27:29.472962 2018] [core:warn] [pid 11677] AH00114: Useless 
use of AllowOverride in line 173 of /etc/httpd/conf/httpd.conf. 
 expires_module (shared)

Response Headers

Cache-Control:max-age=0, no-cache, no-store Connection:keep-alive Content-Encoding:gzip Content-Language:en Content-Length:11829 Content-Type:text/html; charset=UTF-8 Date:Thu, 11 Jan 2018 22:50:43 GMT Expires:Thu, 11 Jan 2018 22:50:43 GMT

  • You are sure the mod_expires module is enabled? – Neograph734 Jan 11 '18 at 20:19
  • I believe so. This is the command I ran. >httpd -M | grep expire [Thu Jan 11 15:27:29.472962 2018] [core:warn] >[pid 11677] AH00114: Useless use of AllowOverride in line 173 of >/etc/httpd/conf/httpd.conf. expires_module (shared) – – mike_g Jan 11 '18 at 20:38
  • First of all, there's more to browser caching than just the expires header. For instance, MDN tells us that the Expires header is ignored when a Cache-Control:max-age header is present. Also, if you say it doesn't work, explain why you think it doesn't. Post the response headers of your front page. Not only the headers of the initial request, but also the headers of assets like images or CSS files. – marcvangend Jan 11 '18 at 21:28
  • Response Headers Cache-Control:max-age=0, no-cache, no-store Connection:keep-alive Content-Encoding:gzip Content-Language:en Content-Length:11829 Content-Type:text/html; charset=UTF-8 Date:Thu, 11 Jan 2018 22:50:43 GMT Expires:Thu, 11 Jan 2018 22:50:43 GMT – mike_g Jan 11 '18 at 22:55
  • Apache configuration has no effect on the response from Drupal, that's only about static files. If drupal doesn't return a cacheable page if you enable it in the performance page as an anoymous user, then you have a module like captcha that prevents caching – Berdir Jan 18 '18 at 21:32

Your Answer

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

Browse other questions tagged or ask your own question.