Problem Enabling Browser Caching
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!
Header set Cache-Control "max-age=84600, public"
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"
Is there a common WHM/Cpanel issue that could be preventing the caching from being enabled?
-
Do you have any caching plugin installed with your wordpress installation ? plugins like W3Total Cache can fulfill your requirements. 0 -
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 0 -
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. 0 -
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: ## Cache-Control # 1 YEAR Header set Cache-Control "max-age=29030400, public"
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:# Enable GZIP Compression. SetOutputFilter DEFLATE # 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 # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary
and also tweak your security:# 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"0
Please sign in to leave a comment.
Comments
4 comments