cPanel: Optimize Your Website using cPanel
In this article, we will show you how to enable website compression using the mod_deflate function on our server automatically compress specified types of content when visitors access that content.
Configuring Optimization via .htaccess
For this demonstration, you will need basic knowledge of htaccess files and how to create/edit them.
1) Login to your account using either (s)FTP, SSH, or the File Manager
2) Create or edit the htaccess file inside of your web root (public_html).
3) Add all or part of the following depending on what filetypes you wish to compress.
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
4) Save the changes.
For more advanced information regarding deflate, please click here.
Malte Horstmann March 25, 2013 at 1:14 am
Just guessing, but should it say “application/x-javascript” in the last line? :)
John Oliver at Site5 March 27, 2013 at 1:41 pm
Hello Malte,
I hope this comment finds you well!
Thank you for pointing that mistake out! I have corrected the article. :)
I hope you have a great day! :)
Jonah May 10, 2013 at 10:25 am
When updating the .htaccess file does this take time to propagate the changes? I’ve updated the file, but PageSpeed is still suggesting that I enable compression. Thanks
Jonah May 10, 2013 at 10:54 am
Nevermind, I needed to place the .htaccess file within the directory that redirected to the root URL.
Antonio November 11, 2013 at 5:56 pm
Hi there,
I have added the following to my .htaccess,
However it does not seam to work.
Could you give me a hand please?
With regards,
Nalesso Antonio
James Davey November 12, 2013 at 9:21 am
Hi Antonio,
Very strange, as that should work normally. I would recommend opening a support ticket with the error you are seeing, and our senior technicians can certainly take a look at it.
Clayton January 29, 2014 at 3:51 pm
Hi There
Just would like to confirm does this work for images?
Thx
James Davey January 29, 2014 at 3:57 pm
Hi Clayton,
It should, yes. Some examples would be as follows:
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
Clayton January 29, 2014 at 3:59 pm
Thanks to try it out
Peter Hammarling March 24, 2016 at 10:00 am
I’m just curious about how this works: what’s the difference between ‘text/xml’ and image/svg+xml? Isn’t an image with .svg suffix treated as an xml text file?
James Davey March 24, 2016 at 11:10 am
Hello Peter,
Essentially, yes
Peter Hammarling March 24, 2016 at 12:33 pm
Thanks James. So would
AddOutputFilterByType DEFLATE text/xml
ensure that svg images are compressed when served?
James Davey March 28, 2016 at 6:00 am
Hello Peter,
It may, but there should be no harm in also adding:
AddOutputFilterByType DEFLATE image/svg+xml
Richard Ambrose April 20, 2014 at 6:07 pm
Worked like a dream.
And as its a multisite, only had to add it to the root htacccess file for it to work for all the other sites, as proved on http://developers.google.com/speed/pagespeed/insights
Fab.
Marlin Gavker November 12, 2014 at 5:36 am
This worked for me. I have a question though, I just read an article (http://www.giftofspeed.com/enable-gzip-compression/ ) which stated that you can also use mod_gzip instead of mod_deflate. Which one do you guys recommend and are there any studies done which of the two has the better compression?
James Davey November 12, 2014 at 6:40 am
Hello Marlin,
Both will work fine, and it really is up to your personal preference. As for which has better compression, that depends on what you’re compressing :) Honestly, your best bet is to try one, then the other, and decide which works best for you.