Optimize Compression for Websites enabled by default - gzip

sahostking

Well-Known Member
May 15, 2012
366
8
68
Cape Town, South Africa
cPanel Access Level
Root Administrator
Twitter
Hi guys,

I would like to know if there is an easy way to enable gzip compression to all new clients. Where the "Optimize Website" option is enabled be default?

For Web Hosting servers I think this is a great to save on bandwidth and if CPU load is not a concern.

Thanks
 

sahostking

Well-Known Member
May 15, 2012
366
8
68
Cape Town, South Africa
cPanel Access Level
Root Administrator
Twitter
That option exists already. But it's disabled by default as per:

Disabled
Compress all content
Compress the specified MIME types

But I want the radio button on for Compress All Content By Default.

I'm trying to maybe get the .htaccess file in skeleton folder. That may work
 

electric

Well-Known Member
Nov 5, 2001
779
8
318
What are the directives in .htaccess to do this?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,203
363
You can enable the "Optimize Website" option for an account and review the .htaccess entries that are added to know exactly what to use. Here is the default entry added on a test system when selecting "Compress All Content":

Code:
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        
        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        
        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        
        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        
        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>
    
    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>
Note this is added to /home/$username/.htaccess and not to the .htaccess file within public_html.

Thank you.
 

postcd

Well-Known Member
Oct 22, 2010
717
19
68
So when i want that option "Optimize Website" enabled by default after account creation. I create new file .htaccess in /root/cpanel3-skel/ with above mentioned code? Is it safe way?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,203
363
Yes, it should work as intended but keep in mind that it's going to populate that file even if Mod_Deflate is disabled at some point.

Thank you.