Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Problem Enabling Browser Caching

Discussion in 'Workarounds and Optimization' started by jazee, Sep 15, 2017.

  1. jazee

    jazee Well-Known Member

    Joined:
    Jan 12, 2015
    Messages:
    80
    Likes Received:
    1
    Trophy Points:
    8
    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?
     
  2. Eminds

    Eminds Well-Known Member

    Joined:
    Nov 10, 2016
    Messages:
    267
    Likes Received:
    20
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Do you have any caching plugin installed with your wordpress installation ? plugins like W3Total Cache can fulfill your requirements.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,664
    Likes Received:
    69
    Trophy Points:
    203
    Location:
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,633
    Likes Received:
    1,787
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    198
    Likes Received:
    46
    Trophy Points:
    28
    Location:
    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>
    
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice