The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Optimize Compression for Websites enabled by default - gzip

Discussion in 'Workarounds and Optimization' started by sahostking, Nov 14, 2012.

  1. sahostking

    sahostking Well-Known Member

    Joined:
    May 15, 2012
    Messages:
    300
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Cape Town, South Africa
    cPanel Access Level:
    Root Administrator
    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
     
  2. MilesWeb

    MilesWeb Well-Known Member
    PartnerNOC

    Joined:
    May 23, 2012
    Messages:
    174
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Do you want a option in cPanel so that client can optimize their websites themselves ?
     
  3. sahostking

    sahostking Well-Known Member

    Joined:
    May 15, 2012
    Messages:
    300
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Cape Town, South Africa
    cPanel Access Level:
    Root Administrator
    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
     
  4. sahostking

    sahostking Well-Known Member

    Joined:
    May 15, 2012
    Messages:
    300
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Cape Town, South Africa
    cPanel Access Level:
    Root Administrator
    Tested it by copying a .htaccess file from /home/username into /root/cpanel3-skel/

    Created a dummy package with domain and checked and it got enabled. Sweet! Problem solved for future accounts.
     
  5. electric

    electric Well-Known Member

    Joined:
    Nov 5, 2001
    Messages:
    697
    Likes Received:
    1
    Trophy Points:
    18
    What are the directives in .htaccess to do this?
     
  6. postcd

    postcd Well-Known Member

    Joined:
    Oct 22, 2010
    Messages:
    621
    Likes Received:
    6
    Trophy Points:
    18
    Yes, what are these please? Im interested to do the same
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  8. postcd

    postcd Well-Known Member

    Joined:
    Oct 22, 2010
    Messages:
    621
    Likes Received:
    6
    Trophy Points:
    18
    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?
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page