B
B
ben1872017-11-24 11:07:22
linux
ben187, 2017-11-24 11:07:22

Why doesn't gzip speed up site loading time?

I read about the loading time of site pages and almost everywhere it is written that you can also use gzip to speed up the download. I took a simple nginx configuration as tests:

user nginx;
worker_processes 4;
pid     /run/nginx.pid;
error_log       /var/log/nginx/error.log;
events {
        worker_connections 1024;
}
http {
        access_log      /var/log/nginx/access.log;
        server {
                listen          80;
                server_name	localhost;
    gzip	       	on;
    gzip_types text/html text/plain image/png image/jpeg text/css text/xml text/javascript application/x-javascript application/xml;
                
    location / {
                        root /data/www;
                }
        }
}

In / data / www I threw index.html from ordinary characters, without pictures and other things, weighing 1mb.
As a result, without gzip, I have the following:
5a17d2a07bc06099414643.png5a17d2b31992f976793233.pngEnable gzip:
5a17d2cd08ac2026371919.png5a17d2d97ea24004893490.png
Question - why did the page load time not accelerate? I also tried different gzip options, but the result is the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Grigoriev, 2017-11-24
@Sleuthhound

Question - why didn't the page load time speed up?

Well, probably because you have the gzip compression configured incorrectly.
For example, writing gzip_types image/png image/jpeg is meaningless, because the binary data of the pictures is already compressed and you will not get any winnings.
It is correct to write like this:
http {
   ....
   gzip on;
   gzip_http_version 1.0;
   gzip_min_length 512;
   gzip_buffers 64 8k;
   gzip_comp_level 5;
   gzip_proxied any;
   gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
   ...
}

You can leave nothing in the server { } section if you do not plan to change the parameters.
Then we take curl and check:
we get an answer
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 24 Nov 2017 11:32:00 GMT
Content-Type: text/html
Last-Modified: Tue, 12 Apr 2016 06:48:17 GMT
Connection: keep-alive
ETag: W/"570c9a31-576"
Content-Encoding: gzip

We pay attention to the Content-Encoding field.
For the test, we take the Apache Benchmark utility from the console:
We look at the fields marked in bold, when gzip is turned off, they increase.
Complete requests: 1
Failed requests: 0
HTML transferred: 3025 bytes
Requests per second: 7.80 [#/sec] (mean)
Time per request: 128.249 [ms] (mean)
Time per request: 128.249 [ms] (mean, across all concurrent requests)
Transfer rate: 25.93 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 90 90 0.0 90 90
Processing: 38 38 0.0 38 38
Waiting: 38 38 0.0 38 38
Well, we take Firefox and look at the Transferred and Size fields there, if compression works, then Transferred should be less than Size.

A
Alexey Ukolov, 2017-11-24
@alexey-m-ukolov

Judging by the Network panel, an uncompressed file was transferred - 0.99 Mb.
For example, this page includes the file

https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic&subset=latin,cyrillic

In Network its size is shown as 1.1 Kb, and if saved to disk - 4.1 Kb. That is, the panel shows the real size transmitted over the network. In your case, this means that the compression for this client is not working for some reason.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question