WordPress Cache Leverage Without Plugin Browser Loading Faster .htaccess

Do you want to add caching to your WordPress website easy way you can follow this simple steps on your site caching is a way to make your website faster, browser store all data cache files, so that they don’t have to be downloaded again all this means in short loading time data already store to user browser that can make them load faster and speed up your WordPress site. Let’s speed up and optimize your WordPress website right now.

Step 1: Test your Website Speed

First you want your website speed result as a percentage, this is very important because before this all steps you know your website speed and performance. Test your site on Google PageSpeed Insights to view your current score.

WordPress Cache Leverage without plugin

Step 2: Open up your .htaccess file

Find .htaccess file on located in the root directory of your website, now you are in root directory (if NOT FOUND .htaccess file – satay same location → go top right side → find setting → check ‘Show all hidden files’ ). Now you can access .htaccess file click and edit.

Open up your .htaccess file

Step 3: Edit .htaccess file

You can copy all the codes bellow and paste it on .htaccess file. To set the expiry time of resources such as images, html, javaScript, CSS files requires a slight modification to your file. Set these values as long as it makes sense for your site – 1 month is typically good enough.

#EDITMODIFY
#Customize expires caching start - adjust the period according to your needs
<IfModule mod_expires.c>
  FileETag MTime Size
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
  ExpiresActive On
  ExpiresByType text/html "access 600 seconds"
  ExpiresByType application/xhtml+xml "access 600 seconds"
  ExpiresByType text/css "access 1 month"
  ExpiresByType text/javascript "access 1 month"
  ExpiresByType text/x-javascript "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 application/pdf "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresByType image/jpg "access 1 year"  
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresDefault "access 1 month"
</IfModule>
#Expires caching end

# BEGIN Cache-Control Headers
<IfModule mod_expires.c>
  <IfModule mod_headers.c>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
      Header append Cache-Control "public"  
    </filesMatch>
    <filesMatch "\.(css)$">
      Header append Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
      Header append Cache-Control "private"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
      Header append Cache-Control "private, must-revalidate"
    </filesMatch>
  </IfModule>
</IfModule>

# Disable ETags
<IfModule mod_headers.c>
	Header unset ETag
</IfModule>
slight modification to your file

Step 4: Test Again your Website Speed

Retest your site on Google PageSpeed Insights to view your new score.

Retest your site on Google PageSpeed Insights to view your new score

Resources I used. Consider following these tutorials to better improve your website speed and optimization. Above we’ve shown you a bunch of ways to implement to make sure you are able to leverage browser caching and make sure content that is downloaded is reused over and over again.

Other Popular Articles...

Leave a Comment