So, you’re trying to optimize your site and you’re testing it with the GT Metrix or Pingdom. The results are showing you “Enable compression” and “Leverage browser caching” recommendations. If you don’t know what that means you’ll probably first searching for the WordPress plugin to resolve this problem. Therefore, in this post I’m going to show you how to fix the leverage browser caching and GZIP compression problems without additional plugin.
Step 1: Login to your server and open .htaccess file
You have three simple options to do so.
Option 1: Use cPanel
If your webhosting uses cPanel then log in and open up File manager. Go to the public_html folder and make a right click on the .htaccess file.
Now select Edit. New window opens up and there you can make your modifications. Don’t forget to save changes after you’re done
Option 2: Use your SEO plugin
Some well known SEO plugins have an option to modify .htaccess file with the help of this plugin. For example, if you are using Yoast SEO plugin, go to SEO >> Tools >> File editor.
If you are using Rank Math, go to Rank Mathh >> General settings >> Edit .htaccess
Option 3: Use FTP
In order to use FTP you need FTP address, username and password. Also, you need a rlieable FTP client (Filezilla, Forklift etc.)
So, using your FTP client log in, find the public_html folder and inside it you’ll find the .htacess file.
Step 2: How to Fix Leverage Browser Caching Problem Without Plugin?
Now, if you have opened up the .htaccess file, just paste this code just above “Begin WordPress” phrase. Save the file and you’re good to go.
## LEVERAGE BROWSER CACHING ##
Header unset Pragma
FileETag None
Header unset ETag
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 week"
ExpiresByType text/html "access 0 seconds"
ExpiresByType text/xml "access 0 seconds
ExpiresByType text/json "access 0 seconds
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## END LEVERAGE BROWSER CACHING ##
Step 3: How to Fix GZIP Enable Compression Problem Without Plugin?
Once again, if you have a .htaccess file upen, just paste this code above the “Begin WordPress” phrase. Save it and test.
# GZIP COMPRESSION
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
# END GZIP COMPRESSION