How to optimize website load speed by using data compress

Website load speed optimization is necessary because of two reasons. First, the faster loading site, the greater the likelihood that the visitor will get a positive impression of the visit and will not leave it immediately, tired of waiting, when the page of the site will be displayed. Second, Google and other search engines into consideration website load speed as one of their criteria, when evaluate sites take. Describes how to optimize website load speed via data compress, step by step setup instructions for Apache http server and configuration directives for mod_deflate. То же самое по русски.

Website load speed optimization via data compress

When the page loads, http server can transmit to user’s browser the following data types:

  • a HTML text file with the content of the page.
  • Cascading Style Sheets (CSS) text files with the instructions how and where to display the page elements.
  • javascript text files for user interaction.
  • files containing images or video in special formats.

The first three types of data can be significantly reduced due to compression. And their loading time can be significantly reduced respectively. The image files are already compressed using specialized algorithms. Therefore any attempt to compress them further will not bring any positive results.

My experience shows, that the amount of transmitted data can be reduced by 1/3 or more due to compression or even more, depending on the number of images per page.

There are a lot of different services in the Internet, by which one can analyze  the website load speed. I prefer to use two of them. Google PageSpeed Insights and Pingdom Website Speed Test. The second (Fig. 1) outputs as test result excellent visual chart. Where can be clearly seen how much and which types of files is loaded when the page is displayed. Also how long takes a transfer of each fileand its size (Fig. 2). Usually, a chart is much larger. Here is a small piece only.

website load speed. Fig.1 Load speed test result

Fig.1 Load speed test result

In the settings one can select a place from which the speed will be measured the speed. To obtain the most reliable results is better to make several tests. With the Google service one can get some good advices how to improve website load speed.

website load speed. Fig. 2. Page load diagram

Fig. 2. Page load diagram

Setting Apache to send compressing data

Web site load speed optimization is done by load and setup mod_deflate module. Next, I will describe how to configure Apache to compress transmitted text files. As a result, Web server Apache will send all text files of these types compressed. If these settings cause any problems, the scope of mod_deflate activity can be limited by directives <Directory> … </ Directory>.

  1. Create a secure connection to the server via ssh.
  2. Became a superuser

    #su

  3. Compression is performed by mod_deflate module. One has to be sure that mod_deflate module is present in the Apache shared modules folder. In Redhat (CentOs) Linux all Apache shared modules should be in the directory /etc/httpd/modules or /chroot/httpd/etc/httpd/modules if http server is chrooted. The module is called mod_deflate.so.
  4. Changing to the folder /chroot/httpd/etc/httpd/conf/ or /etc/httpd/conf/

    #cd /chroot/httpd/etc/httpd/conf/

  5. Using text editor vi, vi shall make some changes in the main Apache configuration file:

    #vi httpd.conf

    Find the instructions for downloading Apache modules and uncomment mod_deflate. Should be as it is shown on fig.3. Now Apache will load the module after rereading its configuration file.

    website load speed. Fig. 3 mod_deflate will be loaded

    Fig. 3 mod_deflate will be loaded

  6. Go down and just before ### Section 3: Virtual Hosts copy and pastethe following text:
    # 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/x-javascript
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/css
    
    <Files ~ "\.(htm|html|css|js|php)$">
        SetOutputFilter DEFLATE
    </Files>
    
    DeflateCompressionLevel 9
    
    # This is for some old browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    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>
    

    This is the standard setting for mod_deflate to compress text files transferred Apache to the visitor’s browser. The marked lines are required because some content management systems (CMS), for example WordPress, add some service information after the file type extension (clearly seen in Fig. 2) and mod_deflate directives can not recognize text files to compress.

  7. Thai is it. Check everything ones more and close editor vi.
  8. Give Apache command to reread its configuration files:

    #/etc/init.d/httpd reload

  9. Repeat website load speed tests again.
    website load speed. Fig 4. New test result

    Fig 4. New test result

    website load speed. Fig. 5. The diagram for the second test

    Fig. 5. The diagram for the second test

    We can see that the page size and page load speed significantly improved.

So we are after 10 minutes of hard work have significantly reduced the website load speed due to compression of text files.

To reduce the size of images, and thus the total time, when browser load them, it is necessary to reduce the size and quality to the To reduce the image size, and thus the time of loading, one should reduce the size and quality to the minimum necessary.

Described why and how to optimize website load speed via data compress. Step by step setup instructions for Apache http server to compress transferring data is given.

No comments yet.

Leave a Reply