YSlow tells me site is not compressed even though it is - apache

"Grade F on Compress components with gzip
There are 19 plain text components that should be sent compressed"
I have checked the compression of the main page, as well as all 19 components individually using "http://www.whatsmyip.org/http_compression/" and it shows compression in all of them. Furthermore, I ensured I'm not using a proxy and that "Accepting-Encoding" is gzip/deflate using "http://www.lagado.com/proxy-test". Contrary to these results, the mod_deflate log files is as follows (excerpt):
... "GET / HTTP/1.1" 4498/13306 (33%)
"GET /Home_Page/style.css HTTP/1.1"
-/- (-%) "GET /css/style.css HTTP/1.1" -/- (-%) "GET /css/slimbox.css HTTP/1.1" -/- (-%) "GET
/js/validator_o.js HTTP/1.1" -/- (-%)
...
So it's not compressing the css or js files? My config file is as follows:
<IfModule mod_deflate.c> SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/xml image/svg+xml application/javascript application/x-javascript application/atom_xml application/rss+xml application/xml application/xhtml+xml application/x-httpd-php application/x-httpd-fastphp
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog /etc/httpd/logs/deflate_log deflate </IfModule>
Firefox 3.6.8
Windows 7 Professional
ISP: Rogers

Nevermind, it worked now. I set the modified the config file as follows
# Method 2: Compress all content, manually excluding specified file types
<IfModule mod_deflate.c>
# place filter 'DEFLATE' on all outgoing content
SetOutputFilter DEFLATE
# exclude uncompressible content via file type
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip
<IfModule mod_headers.c>
# properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>
Then did a browser cache reload and checked the log files and it was compressed. Yslow agreed.

Related

Problem with mod_deflate - compressing executable file

When trying to download file with.EXE extension in the site, the files are coming as .GZ
Environment
Centos 7 64
Apache 2.4.6
Changing the file in /etc/httpd/conf/httpd.conf I have already tried using each of these forms below, however, to no avail (I restarted apache and deleted the browser cache on each attempt):
1:
SetEnvIfNoCase Request_URI \.exe$ no-gzip dont-vary
2:
<FilesMatch \.exe$>
SetEnv no-gzip 1
</FilesMatch>
3:
SetEnv mod_deflate off
4:
SetEnv no-gzip off
5:
In the file /etc/httpd/conf.modules.d/00-base.conf I commented:
LoadModule deflate_module modules/mod_deflate.so
6:
I tried to delete the file, but it did not work.
/usr/lib64/httpd/modules/mod_deflate.so
I was reviewing httpd.conf and when I removed the addtype directive (AddType application / x-gzip .tgz .rar .zip .exe .dll) the EXE file was no longer compressed.
I had put this because the browser was taking too long to start the download EXE, in addition, RAR file instead of downloading, was being displayed as a binary in the browser.
So I did the following to solve (I do not know if it was the indicated output, but my knowledge is not enough, I'm new in this area):
<IfModule mod_deflate.c>
# compress text, html, javascript, 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/atom_xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch ^HMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|zip|bz2|rar|exe|pdf|doc|dll|jpg|sit|mp4|mov|mp3|3gp|webm|rm|avi|ogv)$ no-gzip dont-vary
<FilesMatch \.exe$>
ForceType application/exe
Header set Content-Disposition attachment
</FilesMatch>
<FilesMatch \.rar$>
ForceType application/rar
Header set Content-Disposition attachment
</FilesMatch>
</IfModule>

javascript gzip compression

I am using the following code in my .htaccess file kept in the server root to enable gzip compression. However, the javascript is not getting compressed.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
How to enable compression of javascript? I have checked that mod_deflate is enabled and the index page is getting compressed.
My website is hosted here.
We are not treating javascript as a simple text file here. text/javascript should be replaced by application/javascript as shown.
Application/x-javascript was used for IE as it ignored scripts.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
Cheers!

Content-Encoding: gzip doesn't work for text/html Content-Type

I use the config below in my .htaccess. However, whilst other Content-Type get gzipped, the text/html Content-Type doesn't. Anyone knows why?
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</IfModule>
Try to insert the AddType for html before it, like:
AddType text/html .html .htm
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
Here you have a complete list of MIME types: http://www.htaccess-guide.com/adding-mime-types/
*Edit: Try to change the rule then:
<ifModule mod_deflate.c>
<filesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
I ran across this while having the same issue on a Magento site. In my case the answer was to enable zlib output compression in php.ini because the html was being dynamically generated.
For me it was because of the charset. Whereas:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json
did not work,
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json application/javascript;charset=utf-8 text/css;charset=utf-8
worked. I didn't feel like looking for better answers like how I can instruct Apache to parse out the charset from the content type and I figured that just giving the whole String as is should work. Fortunately it did for me.

Apache mod_deflate: Curl VS everything else

I hope someone can help me with this as it's driving my crazy.
I have set up mod_deflate on a server, everything SEEMS to be set up correctly, however when I access a CSS or JavaScript file via a browser it's saying the files are not compressed.
However, When I do a curl request, the response headers are saying the file is being compressed.
YES, the module is installed and enabled as it is successfully logging:
When I request the file via a browser (Chrom, FF etc), wget, or any of the online page speed tests, it logs something like
"GET /var/cache/_2c95fa0249c997011610ad7ddd3332a8.css HTTP/1.0" gzip, deflate -/- (-%)
When I request via curl, it provides a log like
"HEAD /var/cache/_2c95fa0249c997011610ad7ddd3332a8.css HTTP/1.0" gzip, deflate 108466/358074 (30%)
Is there a way to check to see if mod_deflate is actually working? Am I missing something in the setup of mod_deflate? Could there be a conflict with the expires directive and mod_deflate (I have removed everything but the mod_deflate and it still didn't work)?
Here are the configurations I have set up:
main conf file
<IfModule mod_deflate.c>
DeflateCompressionLevel 4
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{Accept-Encoding}i %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate
</IfModule>
.htaccess file
<FilesMatch "\.(css|js)$">
Allow from all
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
Header unset ETag
Header unset Last-Modified
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:pdf|avi|mov|mp3|mp4|rm)$ no-gzip dont-vary
#Dealing with proxy servers
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
The file in question:
http://diva.akqire.com/var/cache/_2c95fa0249c997011610ad7ddd3332a8.css
Add the following header:
Header set Content-Encoding x-deflate
Apache servers don't send the Content-Length response header if gzip encoding is used.
Is there a way to check to see if mod_deflate is actually working?
Use a custom log to track deflate usage:
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate
References
Configuring mod_deflate
Mod Deflate - Compress Your Web Pages and Save Bandwidth
How To Save Traffic With Apache2's mod_deflate

videos not playing in Flowplayer after configuring mod deflate

I configured Apache/2.2.17 server on Windows 7 with mod deflate configured in .htaccess as
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(?:exe|t?gz|zip|bz2|sit|rar)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
But everything worked fine except videos were not playing in Flowplayer so I changed (added SWF in exclude from gzip compression ) in .htaccess to
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(?:exe|t?gz|zip|bz2|sit|rar|swf)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Now the video plays in flowplayer in all browsers except IE.
I want correct configuration to work in IE also.
The following config worked.
# force deflate for mangled headers
# 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>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>