How to Speed up WordPress Leveraging Browser Caching via .htaccess

Leverage browser caching to make your webpages faster.Are you looking for leverage browser caching .A web browser retrieves a lot of resources from the server like CSS files, Images and html files etc.

speed and get better search engine rankings. This article shall cover how to speed up WordPress by leveraging browser cache via htaccess file.

Editing your htaccess file

In your WordPress root location, find the htaccess file.  Always make a backup before editing the htaccess file. You can download a copy via FTP, save a backup and edit then upload the modified version. Edit the file directly using; Cpanel from your host account.

In this article, WordPress SEO WordPress plugin is used to make the changes in the htaccess file.

In the text editor, it opens the .htaccess file. Paste the code and Save changes

Speed up WordPress

How to Speed up your WordPress

You can copy the below code and paste it into your htaccess file. Once you’ve done that, save your htaccess file and enjoy faster loading speeds.

Here is a complete .htaccess file we have it on Stackwordpress root folder.

######### Stackwordpress SETTING - START  ##########
Options All -Indexes
# Disable ETags
	Header unset ETag
    Header set Connection keep-alive
FileETag None
 
############## MaxCDN Fix #############

  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  

 
########### REDIRECT TRAFFIC TO HTTPS ############
# RewriteEngine On
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 
############ SECURITY ###########
<FilesMatch "\.(md|exe|sh|bak|inc|pot|po|mo|log|sql)$">
Order allow,deny
Deny from all

Allow from all
############## CACHING-GZIP ############

ExpiresActive On
ExpiresDefault A2592000
 
<FilesMatch "\.(txt|xml|js)$">
ExpiresDefault A2592000
 
<FilesMatch "\.(css)$">
ExpiresDefault A2592000

<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$">
ExpiresDefault A2592000

<FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
ExpiresDefault A2592000

  <FilesMatch "\.(txt|xml|js)$">
   Header set Cache-Control "max-age=2592000"  
 
  <FilesMatch "\.(css)$">
   Header set Cache-Control "max-age=2592000"
 
  <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$">
   Header set Cache-Control "max-age=2592000"
 
  <FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
   Header set Cache-Control "max-age=2592000"
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        AddOutputFilterByType DEFLATE "application/atom+xml" \
                          "application/javascript" \
		"application/json" \
		"application/ld+json" \
		"application/manifest+json" \
		"application/rdf+xml" \
		"application/rss+xml" \
		"application/schema+json" \
		"application/vnd.geo+json" \
		"application/vnd.ms-fontobject" \
		"application/x-font-ttf" \
		"application/x-javascript" \
		"application/x-web-app-manifest+json" \
		"application/xhtml+xml" \
		"application/xml" \
		"font/eot" \
		"font/opentype" \
		"image/bmp" \
		"image/svg+xml" \
		"image/vnd.microsoft.icon" \
		"image/x-icon" \
		"text/cache-manifest" \
		"text/css" \
		"text/html" \
		"text/javascript" \
		"text/plain" \
		"text/vcard" \
		"text/vnd.rim.location.xloc" \
		"text/vtt" \
		"text/x-component" \
		"text/x-cross-domain-policy" \
		"text/xml"

AddEncoding gzip              svgz
######### Stackwordpress SETTING END ############
 
# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Conclusion
It does not matter which method you use to speed up your WordPress site but that your site loads faster and your user experience improves. By the above changes to the .htaccess file, your site speed is improved. You end up boosting SEO ratings.

Social Share

Leave a Comment