This article applies to our Linux Shared Hosting servers, where browser content compression/mod_deflate is enabled.
[Pay particular attention to the "PHP: ob_start(ob_gzhandler)" section]
GZIP Compression (mod_deflate)
It is possible to utilize mod_deflate with your website, however you will need to implement the correct configuration that suits your website - where:
- You may need to implement .htaccess directives to suit your deployment:
- See Sample Rules below.
- You may need to install plugins to utilize mod_deflate:
- See Dynamic Content below.
Implementing the required directives for your scenario are outside our scope, as such you will need to consult the support documentation/forums etc. of the website/installation/plugins to determine how to enable GZIP compression.
Both the .htaccess file and website have to be crafted in such a way to enable GZIP compression.
In the case of Wordpress, Joomla and other CMS, you typically will need to either install a caching plugin - or similar, or enable functions in the installation, to allow for GZIP compression of the Dynamic content.
As an example for Wordpress, the following popular plugins can cater for this:
- WP Super Cache
- W3 Total Cache
Use these plugins at your own risk.
Some plugins do not output the minimal rules required for Static file compression, such as the sample rules below; you may need to add these also alongside your plugin's rules to enable compression on static files.
There is also cases where some test websites, and even the plugin themselves, may not pickup that the "Dynamic"/HTML content is compressed; to resolve this you simply add the following to a "php" file that is loaded by the website - usually a configuration file.
For instance you can add the following to the top of your Wordpress "wp-config.php" file:
If using the following plugins you must add the above to your "wp-config.php" file:
- WP Super Cache
The following .htaccess directives are typical for common static files:
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/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/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 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
- Testing Dynamic Content may show that GZIP compression is NOT enabled:
- As such, the best way to test these directives is to check against a static file e.g. a html file.
- For example: domain.tld/readme.html
- Note: You will need to create the file, if it does not exist.
- If you find that the directives enable GZIP for static files, but not Dynamic Content, then you will need to add additional directives/plugins etc. to allow for this.
- .htaccess directives apply from the top folder down i.e.
- If you place the directives in the httpdocs, they will apply to all locations under that folder.
- However, you can potentially override them in .htaccess files below that location.
If you require further assistance with this, please email email@example.com with a brief explanation of the issue and examples/errors which can help replicate the issue.