Why doesn't gzip speed up website loading times?

  • 0
    I read about the loading time of pages of sites and almost everywhere it is written that to speed up loading, you can also use gzip. 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:
    I turn on gzip:

    The question is - why hasn't the page load time accelerated? I also tried different gzip options, but the result is the same.
    Linux Leah Velez, Nov 11, 2020

  • 2 Answers
  • 0
    Question - why didn't page load times get faster?

    Well, probably because your gzip compression is not configured correctly.

    For example, writing gzip_types image / png image / jpeg is pointless, because the binary data of the pictures is so compressed and you won't get any winnings.

    Correctly write 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 may not write anything in the server {} section if you do not plan to change the parameters.

    Then we take curl and check:
    curl -H "Accept-Encoding: gzip,deflate" -I http://mysite.ru/index.html

    we get the 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

    Pay attention to the Content-Encoding field

    For the test from the console, we take the Apache Benchmark utility:
    ab -n 1 -H "Accept-Encoding: gzip,deflate" http://mysite.ru/index.html

    We look at the fields marked in bold, when gzip is off, they increase.

    Concurrency Level: 1
    Time taken for tests: 0.128 seconds

    Complete requests: 1

    Failed requests: 0
    Total transferred: 3405 bytes

    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
    Total: 128 128 0.0 128 128

    Well, let's take Firefox and look at the Transmitted and Size fields, if the compression works, then the Transmitted should be less than the Size.

  • 0
    Judging by the Network panel, an uncompressed file was transferred - 0.99 Mb.

    For example, this page includes the file

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

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!