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

Related Posts: You may like

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

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.