Page 1 of 1

.htaccess help needed for gzip compression

Posted: Wed Mar 19, 2014 5:26 am
by Andaho
I want to enable gzip compression, but I have no idea what I'm doing...

I'm totally confused because I have read to do it 4 different ways! -

Code: Select all

Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
Header set Expires "Fri, 21 Dec 2100 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</FilesMatch>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/javascript text/plain text/xml application/xml text/css application/x-javascript application/javascript
</IfModule>

Code: Select all

# compress text, HTML, JavaScript, CSS, and 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
 
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Code: Select all

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Code: Select all

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
All 4 are completely different! - can anyone help me understand the differences? - and which one is best to use?

Re: .htaccess help needed for gzip compression

Posted: Wed Mar 19, 2014 6:47 am
by Andaho
Ok, no reply yet :( I'm still reading about this for the last 2 hours...

I'm trying to put together the best of what I've barely learned... is this best to use?

Code: Select all

# gzip #
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/javascript text/plain text/xml application/xml text/css application/x-javascript application/javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
# gzip end #

Re: .htaccess help needed for gzip compression

Posted: Wed Mar 19, 2014 6:59 am
by victorj
Just go into admin select system settings server.
scroll down til you see gzip, enter a number of compression and save

Re: .htaccess help needed for gzip compression

Posted: Wed Mar 19, 2014 7:02 am
by Andaho
victorj wrote:Just go into admin select system settings server.
scroll down til you see gzip, enter a number of compression and save
Yep, I did that, but it only compressed the root... all the css and js files were still uncompressed.

Re: .htaccess help needed for gzip compression

Posted: Thu Apr 10, 2014 8:31 pm
by Dunald
Did you get a solution to the css and js compression? I also have the same problem, please advice.

Re: .htaccess help needed for gzip compression

Posted: Thu Apr 10, 2014 8:45 pm
by Andaho
Dunald wrote:Did you get a solution to the css and js compression? I also have the same problem, please advice.
Hi Dunald,

I used the following code for setting cache and gzip compression:

Code: Select all

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 week"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

# gzip #
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/javascript text/plain text/xml application/xml text/css application/x-javascript application/javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
# gzip end #