Gzip compression – custom .htaccess code

Home Forums BulletProof Security Pro Gzip compression – custom .htaccess code

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #12920
    Chris Moon
    Participant

    Ed,

    I ran a GTmetrix test on my site and was advised to add Gzip compression to speed it up

    and this is the code I was told to add to my .htaccess file:

    # compress text, HTML, JavaScript, CSS, and XML
    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
    
    # remove browser bugs
    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

    Got two questions:
    1. Will adding this compromise security on my site?
    2. Which .htaccess file should it be added to?

    regards,
    Chris Moon

    #12923
    AITpro Admin
    Keymaster

    Nope, adding cache code will not compromise or affect your security in any way.  This caching code is similar to our Speed Boost cache code in the link below.

    http://forum.ait-pro.com/forums/topic/htaccess-caching-code-speed-boost-cache-code/

    You can either use this cache code or the Speed Boost cache code and follow the instructions in the link above to add this code to BPS Custom Code.

    #12924
    Chris Moon
    Participant

    Thanks Ed I’ll try your speed boost code

     

    #12926
    AITpro Admin
    Keymaster

    Yep, works great on all our sites.  We had a lot of issues with caching plugins in the past so we needed and created a solution that would not cause any website problems for us.

    #24037
    Joseph Lee
    Participant

    I have a question about this: “You can either use this cache code or the Speed Boost cache code…” http://forum.ait-pro.com/forums/topic/gzip-compression-custom-htaccess-code/#post-12923. Does that mean I should remove the BPS Browser Speed Boost Code if I add the “Remove Browser Bugs” code? Or, does that mean I have to choose between BPS Browser Speed Boost and Gzip?

    # remove browser bugs
    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
    #24042
    AITpro Admin
    Keymaster

    It means that the BPS Speed Boost Cache code already contains that code so adding it twice would be redundant.  The code below is at the bottom of the BPS Speed Boost Cache code and is the same code/does the exact same thing.  It is always possible to add additional conditions to any code, but you probably do not want to use duplicate/redundant code just in case it causes some sort of performance problem.

    # Drop problematic browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
    #24045
    Joseph Lee
    Participant

    Ah, I thank you. I had tried to study all of that a bit but had missed that redundancy!

    One more question: Do I only need to be concerned about ‘gzip-only-text/html’ and just ignore these others?
    text/plain
    text/xml
    text/css
    text/javascript

    I ask because I plan to add this as suggested by the Zen Cache plugin and it has those others in it:

    <IfModule deflate_module>
    	<IfModule filter_module>
    		AddOutputFilterByType DEFLATE text/plain text/html
    		AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd
    		AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml
    		AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript
    		AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf
    		AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf
    	</IfModule>
    </IfModule>
    #24049
    AITpro Admin
    Keymaster

    For the problematic browser section of code you do not need to add anything else.  The BPS Speed Boost Cache code has all of the standard content types, but you can add additional content types or you can mix and match or you can roll your own.  ie use some of the BPS Speed Boost Cache code and not other portions of it and instead use your own caching code.

    http://httpd.apache.org/docs/2.2/mod/mod_deflate.html

    Description: Compress content before it is delivered to the client
    Status: Extension
    Module Identifier: deflate_module
    Source File: mod_deflate.c

    Summary

    The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.

    #24053
    Joseph Lee
    Participant

    Once again I am impressed and pleased to discover BPS already had me covered. It just took me a while to catch on.

    Many thanks!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.