diff --git a/README.md b/README.md index 8b05ff9..92cfea3 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) @@ -190,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. @@ -295,6 +255,56 @@ 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. + + + +```apacheconf + +#For Apache 2.2 + +# 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 Apache 2.4 + + +# 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](http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress) ## Miscellaneous