Lessons

Using the modern HTTP2 protocol to speed up the site

The HTTP2 protocol was published in 2015 and today has full support by all modern browsers. Its use speeds up the download by an average of 23%.

However, web servers like nginx and apache use an outdated version of HTTP1 by default.1. To enable HTTP2, you need to make the appropriate settings.

Article on configuring Nginx and Apache.

Demonstration of the difference in page loading time with and without using the HTTP2 protocol:

Demonstration
PHP code
HTML code
<?php
$mode = $_GET['mode'] ?? '';
?><!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .product-grid {
                display: grid;
                grid-template-columns: 1fr 1fr 1fr 1fr;
                font-size: 20px
            }
            .product-grid img {
                width: 100%;
            }
            .product-grid .product {
                position: relative;
            }
            .product-grid .time {
                position: absolute;
                left: 5px;
                top: 5px;
                background-color: #fff;
                padding: 1px 4px;
            }
            .btn {
                color: #000;
                text-decoration: none;
                padding: 5px 10px;
                border: 1px solid #000;
                border-radius: 5px;
            }
            .btn:hover {
                background-color: #ddd;
            }
            .btn.active {
                background-color: #000;
                color: #fff;
            }
        </style>
        <script>
            // Функция, которая добавляет на изображение время окончания загрузки
            function endLoading(el) {
                var time = performance.now()/1000;
                el.parentNode.insertAdjacentHTML("beforeend", '<div class="time">'+time+' с</div>');
            }
            window.addEventListener("load", (event) => {
                document.querySelector('#page-load').innerHTML = 'Страница загрузилась (событие window.onload) за <b>'+(performance.now()/1000)+'с</b>.';
            });
        </script>
    </head>
    <body style="font-family: sans-serif;">
        Режим: <a class="btn <?=$mode === '' ? 'active' : ''?>" href="./found.php">HTTP 2</a> <a class="btn <?=$mode === '1.1' ? 'active' : ''?>" href="./found.php?mode=1.1">HTTP 1.1</a>
        <p>На странице 5.41 МБ изображений. При отложенной событие window.load отрабатывает сразу.</p>
        <p id="page-load">Тут отобразится время загрузки страницы (вызова события window.onload)</p>
        <div class="product-grid">
<?php for($i = 0; $i < 100;++$i) { ?>
<div class="product">
    <img src="https://<?=isset($_GET['mode']) && $_GET['mode'] === '1.1' ? 'worker1.site-alarm.com/' : 'site-alarm.com/course-example/' ?>photo.jpg?t=<?=microtime(true)+$i?>" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<?php } ?>
        </div>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .product-grid {
                display: grid;
                grid-template-columns: 1fr 1fr 1fr 1fr;
                font-size: 20px
            }
            .product-grid img {
                width: 100%;
            }
            .product-grid .product {
                position: relative;
            }
            .product-grid .time {
                position: absolute;
                left: 5px;
                top: 5px;
                background-color: #fff;
                padding: 1px 4px;
            }
            .btn {
                color: #000;
                text-decoration: none;
                padding: 5px 10px;
                border: 1px solid #000;
                border-radius: 5px;
            }
            .btn:hover {
                background-color: #ddd;
            }
            .btn.active {
                background-color: #000;
                color: #fff;
            }
        </style>
        <script>
            // Функция, которая добавляет на изображение время окончания загрузки
            function endLoading(el) {
                var time = performance.now()/1000;
                el.parentNode.insertAdjacentHTML("beforeend", '<div class="time">'+time+' с</div>');
            }
            window.addEventListener("load", (event) => {
                document.querySelector('#page-load').innerHTML = 'Страница загрузилась (событие window.onload) за <b>'+(performance.now()/1000)+'с</b>.';
            });
        </script>
    </head>
    <body style="font-family: sans-serif;">
        Режим: <a class="btn active" href="./found.php">HTTP 2</a> <a class="btn " href="./found.php?mode=1.1">HTTP 1.1</a>
        <p>На странице 5.41 МБ изображений. При отложенной событие window.load отрабатывает сразу.</p>
        <p id="page-load">Тут отобразится время загрузки страницы (вызова события window.onload)</p>
        <div class="product-grid">
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329770.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329771.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329772.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329773.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329774.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329775.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329776.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329777.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329778.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329779.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329780.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329781.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329782.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329783.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329784.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329785.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329786.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329787.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329788.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329789.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329790.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329791.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329792.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329793.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329794.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329795.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329796.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329797.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329798.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329799.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329800.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329801.5783" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329802.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329803.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329804.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329805.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329806.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329807.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329808.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329809.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329810.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329811.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329812.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329813.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329814.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329815.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329816.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329817.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329818.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329819.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329820.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329821.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329822.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329823.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329824.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329825.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329826.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329827.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329828.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329829.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329830.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329831.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329832.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329833.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329834.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329835.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329836.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329837.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329838.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329839.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329840.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329841.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329842.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329843.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329844.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329845.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329846.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329847.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329848.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329849.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329850.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329851.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329852.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329853.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329854.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329855.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329856.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329857.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329858.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329859.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329860.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329861.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329862.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329863.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329864.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329865.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329866.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329867.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329868.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://site-alarm.com/course-example/photo.jpg?t=1768329869.5784" onload="endLoading(this)" /><br />
    Товар 1<br />
    1000 руб.
</div>
        </div>
    </body>
</html>

Check your website
It's free and will take from 11 to 70 seconds

We use cookies. By continuing to use the site, you agree to the processing of personal data in accordance with privacy policy. I agree