From 85b96a45a3aa9ecab7a3257b3501d88d7822e487 Mon Sep 17 00:00:00 2001 From: Jude Rosario Date: Tue, 10 Feb 2015 16:40:54 +0530 Subject: [PATCH 1/4] Added Snippets for Compression --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/README.md b/README.md index 8b05ff9..0569269 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ A collection of useful .htaccess snippets, all in one place. I decided to create - [Compress Text Files](#compress-text-files) - [Set Expires Headers](#set-expires-headers) - [Turn eTags Off](#turn-etags-off) + - [Enable gzip Compression](#enable-gzip-compression) - [Miscellaneous](#miscellaneous) - [Set PHP Variables](#set-php-variables) - [Custom Error Pages](#custom-error-pages) @@ -295,6 +296,55 @@ By removing the ETag header, you disable caches and browsers from being able to FileETag None ``` +### Enable gzip Compression + +Gzipping an easy way to reduce weight per page of your site. + +For `httpd-2.2` and below + +```apacheconf +# Compress Text, HTML , JS, 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 +``` +For `httpd-2.4` and up + +``` +# Declare a filter, which runs after all internal filters like PHP or SSI +FilterDeclare gzip CONTENT_SET + +# The "gzip" filter can change "Content-Length", can not be used with range requests +FilterProtocol gzip change=yes;byteranges=no + +# Enable "gzip" filter if "Content-Type" contains Text, HTML , JS, CSS, XML: +FilterProvider gzip DEFLATE resp=Content-Type $text/plain +FilterProvider gzip DEFLATE resp=Content-Type $text/html +FilterProvider gzip DEFLATE resp=Content-Type $text/css +FilterProvider gzip DEFLATE resp=Content-Type $text/javascript +FilterProvider gzip DEFLATE resp=Content-Type $application/javascript +FilterProvider gzip DEFLATE resp=Content-Type $application/x-javascript +FilterProvider gzip DEFLATE resp=Content-Type $application/xhtml+xml +FilterProvider gzip DEFLATE resp=Content-Type $application/rss+xml +FilterProvider gzip DEFLATE resp=Content-Type $application/xml + +# Add "gzip" filter to the chain of filters +FilterChain gzip +``` +[Source: SoftScibe](http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress) +[Source: SO](http://stackoverflow.com/questions/5230202/apache-addoutputfilterbytype-is-deprecated-how-to-rewrite-using-mod-filter) ## Miscellaneous From 5e8d4697ad5124528acb1c7fd758a5c4d3c2be49 Mon Sep 17 00:00:00 2001 From: Jude Rosario Date: Tue, 10 Feb 2015 16:46:24 +0530 Subject: [PATCH 2/4] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0569269..44fd9a3 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ FileETag None Gzipping an easy way to reduce weight per page of your site. -For `httpd-2.2` and below +For `httpd-2.2` ```apacheconf # Compress Text, HTML , JS, CSS, XML: @@ -320,9 +320,9 @@ AddType x-font/woff .woff AddType image/x-icon .ico AddType image/png .png ``` -For `httpd-2.4` and up +For `httpd-2.4` and up, in apache 2.2 you should enable `filter_module` and `deflate_module`. -``` +```apacheconf # Declare a filter, which runs after all internal filters like PHP or SSI FilterDeclare gzip CONTENT_SET @@ -343,8 +343,7 @@ FilterProvider gzip DEFLATE resp=Content-Type $application/xml # Add "gzip" filter to the chain of filters FilterChain gzip ``` -[Source: SoftScibe](http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress) -[Source: SO](http://stackoverflow.com/questions/5230202/apache-addoutputfilterbytype-is-deprecated-how-to-rewrite-using-mod-filter) +[Source](http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress) ## Miscellaneous From 2da8c0f2588b5bc010d81aca11ac13aa8021bfa9 Mon Sep 17 00:00:00 2001 From: Jude Rosario Date: Tue, 10 Feb 2015 21:53:35 +0530 Subject: [PATCH 3/4] Inline comments as suggested by @phanan in #2 --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 44fd9a3..f151cc0 100644 --- a/README.md +++ b/README.md @@ -300,9 +300,12 @@ FileETag None Gzipping an easy way to reduce weight per page of your site. -For `httpd-2.2` + ```apacheconf + +#For Apache 2.2 + # Compress Text, HTML , JS, CSS, XML: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html @@ -319,10 +322,9 @@ AddType x-font/eot .eot AddType x-font/woff .woff AddType image/x-icon .ico AddType image/png .png -``` -For `httpd-2.4` and up, in apache 2.2 you should enable `filter_module` and `deflate_module`. -```apacheconf +# For Apache 2.4 + + # Declare a filter, which runs after all internal filters like PHP or SSI FilterDeclare gzip CONTENT_SET From 30a2c766f87904b675fc79507fc279e3435f15ac Mon Sep 17 00:00:00 2001 From: Jude Rosario Date: Wed, 11 Feb 2015 20:33:00 +0530 Subject: [PATCH 4/4] Removed possible duplicate content. --- README.md | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/README.md b/README.md index f151cc0..92cfea3 100644 --- a/README.md +++ b/README.md @@ -191,47 +191,6 @@ Require valid-user ``` ## Performance -### Compress Text Files -``` apacheconf - - - # Force compression for mangled headers. - # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping - - - 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 - - - - # 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 `` and `` lines - # as `AddOutputFilterByType` is still in the core directives). - - AddOutputFilterByType DEFLATE application/atom+xml \ - application/javascript \ - application/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 - - - -``` -[Source](https://h5bp.com) - ### Set Expires Headers _Expires headers_ tell the browser whether they should request a specific file from the server or just grab it from the cache. It is advisable to set static content's expires headers to something far in the future.