Ben
Ben

Reputation: 1914

apache mod_deflate for css and js

.htaccess

<ifmodule mod_deflate.c>
# compress the files
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

# removes some 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>

And for the php files

 <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler"); else ob_start(); ?>

And for the php files everything is OK but no for css,js files. Any tips ?

Upvotes: 0

Views: 3391

Answers (2)

Jaspreet Chahal
Jaspreet Chahal

Reputation: 2750

In httpd.conf make sure this line is not commented

LoadModule deflate_module modules/mod_deflate.so

if it is then uncomment it and restart the apache service

Upvotes: 1

ionFish
ionFish

Reputation: 1024

To test that mod_deflate is ACTUALLY working, try putting this at the top of your httpd.conf file:

LoadModule deflate_module modules/mod_deflate.so

and in the bottom of your httpd.conf file:

##############################################
#Mod Deflate Config:
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '(%{ratio_info}n%%) "%r" %{output_info}n/%{input_info}n' deflate
CustomLog logs/compression.log deflate
###############################################

This will compress just about anything ONLY if the browser sends the gzip-ready header.

After you get some hits on your site, check "compression.log" in the apache logs folder. Post the output.

Upvotes: 3

Related Questions