Improve website page load speed using htaccess gzip and cache tricks

In this tutorial we are going to talk about how to improve page load speed using htaccess gzip and cache tricks, We all know htaccess is a very powerful file in apache server which control your website behavior, This file is useful in many cases like creating user friendly SEO url’s , Removing extension (.php, .html) or setting your custom extension name So using htaccess you can control your website like boss. Here I am going to show you how you can easily improve your website performance, page load speed, optimize pages and make your website load faster.

Step-1: mod_gzip is an Apache extension that allows to quickly and easily compress web files before send them to the client. This boost your website page load speed.

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

If your website on shared hosting then compression tool already available on your control panel and you just have to enable it.
1. Goto your control panel and you’ll see option like Optimize Website, click on it
2. After that enable compression of all content and update setting.

Step-2: You must use cache control for your website like if first time visitor comes on your website it load whole content of website like JS, CSS, Images, But if you apply cache control for your website it makes easy to load website content faster for returning visitor, and they get better user experience.

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 3 seconds"
  ExpiresByType text/html "access plus 3 seconds"
  ExpiresByType image/gif "access plus 2500000 seconds"
  ExpiresByType image/jpeg "access plus 2500000 seconds"
  ExpiresByType image/png "access plus 2500000 seconds"
  ExpiresByType text/css "access plus 600000 seconds"
  ExpiresByType text/javascript "access plus 200000 seconds"
  ExpiresByType application/x-javascript "access plus 200000 seconds"

Finally set cache control headers.

<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
  <filesMatch "\.(css)$">
    Header set Cache-Control "public"
  <filesMatch "\.(js)$">
    Header set Cache-Control "private"
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"

I hope this htaccess trick will make your website faster and smoother.

If you like this post please don’t forget to subscribe my public notebook for more useful stuff