I have added the following lines in tomcat's conf/server.xml file to enable gzip compression but its not working. Pages are still uncompressesd.
<Connector port="8080"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
Any idea?
I was testing similar
server.xml
changes in my local development environment and was frustrated that it was not working either.My issue was that I was making edits to my local Tomcat installation (C:\apache-tomcat-8.0.5) that I selected when using the
Servers window -> (right-click) -> New -> Server
dialog in Spring Tool Suite.However, when published, the actual tomcat directory being used was located in (workspace folder)\.metadata\.plugins\org.eclipse.wst.server.core\tmp0.
You can check the published location by right-clicking the server and choosing "Browse Deployment Location..."
From there you can update the appropriate
server.xml
file, or you could delete and re-add the server.In my case it didn't worked because of Antivirus (ESET, Windows)
It was binded somewhere before browser. It unpacked body and remove "Content-Encoding" header. For browser response looked like normal not compressed response. Even in Fiddler it was already decompressed.
Https responses were working, but http resposes were decompresed by ESET.
It is not enough. Turn ESET off. I had to go to "advanced settings" -> "Web access protection" -> "HTTP, HTTPS" and turn it off there
If you serve files from hard drive you may need add option useSendFile="false" into connector.
If Tomcat is fronted by Apache on port 80, you will need to enable compression in Apache itself. The compression in Tomcat will only work if you access it directly on port 8080.
On Windows, I encountered this behaviour while trying to temporarily enable content compression in my development environment to gain a rough understanding of the total payload of a page in my application.
I can confirm that ESET NOD32 Antivirus does behave in the way that @bugs_ describes in his answer to this question and I can also confirm that running Fiddler4 has the same effect. However, both closing Fiddler and disabling NOD32's HTTP scanning did not solve the problem, to do that, I had to disable the use of 'sendfile' in my connector as follows:
The important attribute, here, is
useSendfile="false"
I am using Apache Tomcat 8, under Windows. The Tomcat documentation (http://tomcat.apache.org/tomcat-8.0-doc/config/http.html) says the following about
useSendfile
:And this about
compression
: