-
AuthorPosts
-
April 20, 2015 at 2:32 am #253688
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 enablemod_filter
# and can remove the<IfModule mod_filter.c>
and</IfModule>
lines
# asAddOutputFilterByType
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 .pngIs there any significant difference or whatsoever?
April 20, 2015 at 10:31 am #254030Hey 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.
April 20, 2015 at 11:04 am #254059Great, 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>
April 20, 2015 at 12:15 pm #254111This reply has been marked as private.April 20, 2015 at 7:30 pm #254383You can place it after # END WordPress.
April 21, 2015 at 12:50 am #254538Thanks 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>April 21, 2015 at 1:56 am #254586The 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.
April 21, 2015 at 2:30 am #254613crystal clear, thanks!
April 21, 2015 at 2:33 am #254617Please feel free to get in touch with us regarding any further queries about the X theme.
-
AuthorPosts