Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added detailed instructions to enable gzip compression #13

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 51 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -190,47 +191,6 @@ Require valid-user
```

## Performance
### Compress Text Files
``` apacheconf
<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/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>
```
[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.
Expand Down Expand Up @@ -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

Expand Down