Lessons

Title "Keep alive"

A web page consists of dozens of files. Before the download starts, there is a so-called connection setup process. This is a service operation, which is a mandatory action.

The “Keep alive” header tells the browser not to terminate the connection after downloading one file and wait for the rest of the files to download. If this is not done, the browser will waste extra time setting up a new connection for each file.

Demonstration of the difference in download speed when the “Keep alive” header is enabled and disabled:

Demonstration
PHP code
htaccess 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;
                display: inline-block;
                margin-bottom: 5px;
                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="./no_keep_alive.php">Обычный режим</a> <a class="btn <?=$mode === 'disable' ? 'active' : ''?>" href="./no_keep_alive.php?mode=disable">Отключённый заголовок Keep Alive</a>
        <br />
        <p id="page-load">Тут отобразится время загрузки страницы (вызова события window.onload)</p>
        <div class="product-grid">
<?php for($i = 0; $i < 50;++$i) { ?>
<div class="product">
    <img src="https://worker1.site-alarm.com/<?=$mode === 'disable' ? 'photo-http1-1.jpg?t='.(microtime(true)+$i).'&keep-alive=disable' : 'photo.jpg?t='.(microtime(true)+$i)?>" /><br />
    Товар 1<br />
    1000 руб.
</div>
<?php } ?>
        </div>
    </body>
</html>
<If "%{THE_REQUEST} =~ m#photo-http1-1\.jpg#">
    Header set Connection "close"
</If>
<!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;
                display: inline-block;
                margin-bottom: 5px;
                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="./no_keep_alive.php">Обычный режим</a> <a class="btn " href="./no_keep_alive.php?mode=disable">Отключённый заголовок Keep Alive</a>
        <br />
        <p id="page-load">Тут отобразится время загрузки страницы (вызова события window.onload)</p>
        <div class="product-grid">
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883424.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883425.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883426.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883427.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883428.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883429.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883430.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883431.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883432.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883433.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883434.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883435.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883436.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883437.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883438.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883439.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883440.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883441.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883442.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883443.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883444.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883445.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883446.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883447.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883448.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883449.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883450.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883451.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883452.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883453.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883454.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883455.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883456.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883457.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883458.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883459.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883460.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883461.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883462.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883463.1766" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883464.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883465.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883466.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883467.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883468.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883469.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883470.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883471.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883472.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
<div class="product">
    <img src="https://worker1.site-alarm.com/photo.jpg?t=1772883473.1767" /><br />
    Товар 1<br />
    1000 руб.
</div>
        </div>
    </body>
</html>

PRO subscription for working with the service

Promo
Checking 50 pages in the tool "Checking the page"
190 ₽
The subscription is activated for 10 days and is linked to a specific site.
PRO subscription
3,500 pages per week in tools "Checking the page" and "Full site scan".
1 580 ₽
The subscription is activated for 30 days and you can scan any site.
Wallet
Additional pages that are credited to a separate balance. For checking large sites.
200 ₽
Number of pages
An active PRO subscription is required.
We use cookies. By continuing to use the site, you agree to the processing of personal data in accordance with privacy policy. I agree