jazee

Well-Known Member
Jan 12, 2015
124
5
68
cPanel Access Level
Root Administrator
Both Google Pagespeed Insights and GTMetrix are telling me my Wordpress site does not have browser caching enabled. I added the following to the .htaccess file in public_html and it makes no difference!

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=84600, public"
</filesMatch>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>

Is there a common WHM/Cpanel issue that could be preventing the caching from being enabled?
 

dalem

Well-Known Member
PartnerNOC
Oct 24, 2003
2,983
157
368
SLC
cPanel Access Level
DataCenter Provider
is mod_deflate installed on your system
verify via command line

httpd -t -D DUMP_MODULES | grep deflate_module
ea-apache24-mod_deflate
if its not installed
for EA4
yum install ea-apache24-mod_deflate

if still using EA3
use easyapache
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
Hello,

Can you reproduce the same test results with a test page that's not part of your WordPress installation? If not, then you may want to look into WordPress plugins that utilize browser caching.

Thank you.
 

linux4me2

Well-Known Member
Aug 21, 2015
259
78
78
USA
cPanel Access Level
Root Administrator
As noted above, you may have some other issues, but if you get to the point of implementing browser-caching, and want to do it globally for all accounts on your server, I have had good luck with adding the following to WHM -> Service Configuration -> Apache Configuration -> Include Editor -> Pre VirtualHost Include -> All Versions:

Code:
## Cache-Control
<IfModule mod_headers.c>
  # 1 YEAR
  <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=29030400, public"
  </FilesMatch>
</IfModule>
Note that the above doesn't cache *.js, *.css, and *.php files, which may change frequently as sites are developed.

While you're in there, you might also want to enable Gzip compression:
Code:
# Enable GZIP Compression.
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html
       
        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
       
        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
       
        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
       
        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>
   
    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>
and also tweak your security:
Code:
<IfModule mod_headers.c>
  # This setup will give you a "B" on observatory.mozilla.org. To do better, you need to add "Header set Content-Security-Policy", which WP Super Cache breaks.
  # Block site from being framed
  Header always append X-Frame-Options SAMEORIGIN
  # Block pages from loading when they detect reflected XSS attacks in older browsers.
  Header set X-XSS-Protection "1; mode=block"
</IfModule>