View All Posts

Http Compression (GZIP) Methods

Http Compression (GZIP) can make a huge difference in your sites performance and it is very easy to implement.

.htaccess Method
(append this code to the root .htaccess file. )
The ROOT on many servers is in the "/public_html/" folder

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

</IfModule>

 

PHP Method
______________________________________________________________

1) Create a text file named php.ini on your local computer
2) Open the php.ini with your text editor (e.g. Notepad++)
3) Copy the snippet below and paste into php.ini

output_buffering = Off
output_handler =
zlib.output_compression = On

4) Save your php.ini, and upload it to the root directory of your primary domain (usually, it's /public_html/)

For IIS

If your server is IIS, follow these instructions in the Microsoft TechNet document to enable compression.

Posted: December 27th, 2016
Category: Snippets
Tags: , ,