Enabling GZIP compression using htaccess

Enabling GZIP compression can help you reduce the size of your webpage, which can reduce the amount of time to download the resource of webpage, reduce data usage for the client and improve webpage speed.

What is GZIP Compression?

GZIP simply is a file format and used for file compression and decompression. GZIP compression is enabled server-side, and allows user to reduce the file size of your HTML, stylesheets, and JavaScript files. It will not work on images as these are already compressed in a different way but we can enable cache to reduce webpage size for return users . Using enabling GZIP file compression we can reduce up to 70% file size. It is easiest way to optimizations of webpage.

How to Enable GZIP Compression

Here i am enabling GZIP Compression using htaccess file, this code will be enable GZIP and cache of webpage but here i am not setting expiry date of cache file for use it copy and past into htaccess file.

<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.*
</ifModule>

Enable GZIP Compression With Expiry Date

Here i am enabling GZIP Compression using htaccess file, this code will be enable GZIP and cache of webpage with expiry date of cache file for use it copy and past into htaccess file.

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 11 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresDefault "access plus 2 days"
</IfModule>

Note : Don’t set expiry date for long term because of if you set cache expiry date 1 year then you made changes in css file or website design then for return user not visible your latest version or design of website.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts: You may like

All Full Forms Related to Database

List of Free Business Directories

How to disable selection of text on a web page

Google Geochart show list of all countries with multiple colors

List of companies and their Headquarters And CEOs in the world

List of Top 15 Popular Search Engines

What Is A Landing Page Why It’s Important

How to increase website speed

How to redirect 404 error to 404.php page using htaccess

What is the difference between jQuery and Angular JS

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.