Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #253688

    arneverschoor
    Participant

    Hi guys,

    I’m about to activate Gzip compression on my website. Since I’m editing the htaccess file I’d like to check the following with you just to be sure:

    In your performance tutorial the following code is suggested for Gzip compression

    <IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
    <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
    SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
    RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding
    </IfModule>
    </IfModule>

    # Compress all output labeled with one of the following MIME-types
    # (for Apache versions below 2.3.7, you don’t need to enable mod_filter
    # and can remove the <IfModule mod_filter.c> and </IfModule> lines
    # as AddOutputFilterByType is still in the core directives).
    <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
    application/javascript \
    application/json \
    application/ld+json \
    application/rss+xml \
    application/vnd.ms-fontobject \
    application/x-font-ttf \
    application/x-web-app-manifest+json \
    application/xhtml+xml \
    application/xml \
    font/opentype \
    image/svg+xml \
    image/x-icon \
    text/css \
    text/html \
    text/plain \
    text/x-component \
    text/xml
    </IfModule>

    </IfModule>

    However, when I search on the web I find the following code

    # compress text, html, javascript, css, 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
    AddType x-font/otf .otf
    AddType x-font/ttf .ttf
    AddType x-font/eot .eot
    AddType x-font/woff .woff
    AddType image/x-icon .ico
    AddType image/png .png

    Is there any significant difference or whatsoever?

    #254030

    Rubin
    Keymaster

    Hey There,

    Both codes will compress and optimize the site, ours is a bit more complex / more features are turned on but its up to you and your preference which one you want to use.

    #254059

    arneverschoor
    Participant

    Great, thanks. Assuming that I can remove the lines that start with a “#”, do I have to place the following code on a certain position in the htaccess file?

    <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
    SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
    RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding
    </IfModule>
    </IfModule>

    <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
    application/javascript \
    application/json \
    application/ld+json \
    application/rss+xml \
    application/vnd.ms-fontobject \
    application/x-font-ttf \
    application/x-web-app-manifest+json \
    application/xhtml+xml \
    application/xml \
    font/opentype \
    image/svg+xml \
    image/x-icon \
    text/css \
    text/html \
    text/plain \
    text/x-component \
    text/xml
    </IfModule>

    </IfModule>

    #254111

    arneverschoor
    Participant
    This reply has been marked as private.
    #254383

    Christian
    Moderator

    You can place it after # END WordPress.

    #254538

    arneverschoor
    Participant

    Thanks guys. One final thing to confirm:

    Can, or can I not remove the lines of your code that start with an “#”

    For example the bold lines underneath

    <IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping

    <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
    SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
    RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding
    </IfModule>
    </IfModule>

    #254586

    Christian
    Moderator

    The hash tags # is a comment line in htaccess so yes, you can delete it. However, you will have no reference in the future in case you forget what the code does.

    Thanks.

    #254613

    arneverschoor
    Participant

    crystal clear, thanks!

    #254617

    Friech
    Moderator

    Please feel free to get in touch with us regarding any further queries about the X theme.