mod_deflate to compromise my site? - .htaccess

I have this code example to compromise my website with deflate:
<ifModule mod_deflate.c>
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
AddOutputFilterByType DEFLATE application/json
</ifModule>
but I read on my provider site that I have also to insert this rule:
1-**mod_gzip_on Yes ?**is this rule is must or do I have to ignoer it?the code above is sufficient.
my second question is: I read this advise below !!
Some popular browsers cannot handle compression of all content so you may want to set the gzip-only-text/html note to 1 to only allow html files to be compresse. If you set this to anything but 1 it will be ignored.
what I understand that some browsers they don't support compromise, should I insert also the rules below here:
**BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/ht**ml
or just ignore it?

I don't understand your first question but if it's about using mod_deflate over mod_gzip then the answer is to use mod_deflate. Development stopped on mod_gzip years ago and mod_deflate is part of standard Apache and also (despite its name) uses gzip - though can also use the less widely supported deflate option if you want to but that is not recommended.
As to your second question that is no longer necessary either. Some very, very, very old browsers had bugs in them for gzip but now all browsers handle it well and tell Apache if they don't. None of those older browsers are in use anymore and even if they were they probably couldn't open your site for other reasons. See here for gzip browser support: http://schroepl.net/projekte/mod_gzip/browser.htm

Related

Where is .htaccess on AWS EC2 EB

I have an EC2 instance running Elastic Beanstalk. I would like to enable GZIP Compression, and I understand I need to modify my .htaccess file.
I have read that the .htaccess file is located in my root folder of the app install. However, I cannot seem to find it. (I am pretty novice and not sure where the root folder is).
I am able to ssh onto the server running Apache Tomcat 8 with a Java 8 app.
Question
Where is .htaccess located?
This is what I have in my root:
$ ls
bin cgroup etc lib local media opt root sbin srv tmp var
boot dev home lib64 lost+found mnt proc run selinux sys usr
UPDATE
I have a .ebextensions/tomcat-settings.config now that works. It enables GZip compression.
option_settings:
aws:elasticbeanstalk:environment:proxy:
GzipCompression: 'true'
ProxyServer: nginx
aws:elasticbeanstalk:environment:proxy:staticfiles:
/pub: public
This does not seem to compress .svg files though. So if possible, I would like to have the following, but not sure where to add it:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
you need to upload .htaccess file or make it in your ec2 instance on your root folder on that you upload your application, if you are using elastick beanstalk you need to add the .htaccess file to your .zip file on the root folder
How you configured the ec2 instance, by ssh or by the .ebextensions file?
if you configure the instance by ssh and you are using a elastic enviorment then the configuration will be erased when the instance is degraded or change, if you are using only one instance by ec2 the configuration keep working.
if you need to configure it by .ebextensions you need to create a folder named .ebextensions in your .zip file, inside this folder you need to create two files named enable_mod_deflate.conf and myapp.config.
The contents of enable_mod_deflate.conf:
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/gif
AddOutputFilterByType DEFLATE image/jpeg
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
The contents of myapp.config:
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
Then you need to restart the server.

GZIP Compression is working for css/js but not for html

I set up GZIP Compression, it's working for css/js files, but not for html page.
Please help me troubleshoot.
Server have compression enabled, here are info.php stats related to compression:
_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate
Stream Wrapper compress.zlib://
Stream Filter zlib.inflate, zlib.deflate
Compiled Version 1.2.3
Linked Version 1.2.3
Here are the .htacess part:
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
It is compressing css and js. Initially on google page insights test all css, js and page itself were showed as not compressed, now only page itself.
Also here is the screenshot from firefox web developers tool.
What can be a problem?
I am using magento ver 1.9 if it makes difference.
For anybody with same question the problem was that hosting provider didn't enable "zlib.output_compression"
After enabling it the issue is solved.

gzipping my site doesn't seem to work using htaccess - no Content-Encoding: gzip

I'm trying to gzip my site. But I'm not sure if it's actually working..
When I'm checking at checkgzipcompression.com, WhatsMyIP.org and YSlow - they all tell me that the site is not compressed. Yslow also tells me that I have a couple of files that is not compressed, and of course suggest I do so.
This is the part, in my htaccess-file, that should compress the site:
<IfModule mod_deflate.c>
# Force compression for mangled headers.
<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
<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/x-httpd-php \
application/x-httpd-fastphp \
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>
This code is based on h5bp (https://github.com/h5bp/html5-boilerplate/blob/v4.3.0/doc/TOC.md).
If I add ini_set("zlib.output_compression", 4096); to the PHP initiation script - both checkgzipcompression.com and WhatsMyIP.org tells me that my site is compressed. Along with the page weight in kb.
But YSlow still tells me that I have multiple files that is not compressed.
And in developer tools for both chrome and firefox shows the uncompressed filesize for each request/file (I'm not sure if that's how it suppose to be though(?)).
It does say Accept-Encoding: gzip,deflate, and Vary: Accept-Encoding, but nothing like Content-Encoding: gzip.
I just had a chat with my server provider -- BlueHost -- and they said that mod_deflate runs automatically on all of their servers. But since it's dynamic, most website scanners don't see it.
The conclution was that it's not possible for me to actually be sure that my site is in fact compressed.
The .htaccess-file is as it's shown above, and zlib.output_compression() is turned off - in case you have the ability to check it out..
The domain is: http://barkeeper.thomaskile.me
Here's a acreenprint of what firefox has to say about the page:
Same issue with Bluehost. I checked the actual file sizes and they are not compressed. Got the same BS that it automatic. First they tried telling me it only worked when the server was under a heavy load... apparently that person was clueless. Then I was told the server load threshold was low, and that compression was disabled when that threshold was exceeded. I am quite upset with these answers being all over the place.

PageSpeed and YSlow don't recognize gzip

I know this question has been asked several times on stackoverflow, but I couldn't find anything that worked for me in those questions.
I have a website hosted by BlueHost, and I am trying to enable gzip compression.
Here is (the relevant part of) my .htaccess file:
#GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript application/x-javascript text/plain text/html text/css text/x-component text/xml application/json application/xml alpplication/xhtml+xml
</ifmodule>
This code was given to me by BlueHost.
If I run Google's PageSpeed Insights, it recognizes the compression. However, when I run GTMetrix (which does PageSpeed and YSlow), neither of them recognize the gzip'd content. Also, I checked on http://www.gidnetwork.com/tools/gzip-test.php and I am serving gzip'd content.
Did I do something wrong, or does GTMetrix have a bug?

Htaccess Concatenarion

I use this code to concatenare CSS and Javascript:
<FilesMatch "\.combined\.js$">
Options +Includes
AddOutputFilterByType INCLUDES application/javascript application/json
SetOutputFilter INCLUDES
</FilesMatch>
<FilesMatch "\.combined\.css$">
Options +Includes
AddOutputFilterByType INCLUDES text/css
SetOutputFilter INCLUDES
</FilesMatch>
but it doesnt work
So you're using
<!--#include file="path/to/a/file.js" -->
<!--#include file="path/to/another/file.js" -->
in a master JS or CSS file, right?
This is what is being enabled by the .htaccess code posted in your question.
I also used same code for concatenating my js and css file. It works pefectly in my local machine..but don't work in live. I am using ubutu linux server.

Resources