Lessons

The sequence of connecting JavaScript files

The page consists of dozens of files. They are loaded in the order in which they are listed in the HTML code of the page. JavaScript is responsible for the interactive part of the page, and CSS and images for the visual.

The sooner the user sees the graphic elements and content, the sooner he starts studying it, the higher the page conversion will be. To prevent JavaScript files from delaying the display of page graphics, transfer the connection of JavaScript files at the end of the page, after CSS files and images.

Below is an example of the difference between enabling JavaScript at the beginning and at the end of a page.

Demonstration
PHP code
HTML code
<?php
$mode = $_GET['mode'] ?? 'start';

$jsHtml = '';
for($i = 0; $i < 100;++$i) {
    $jsHtml .= '<script src="./10-kb-js.js?t='.microtime(true).'.'.$i.'"/></script>'."\n";
}

?><!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .product img {
                max-width:100%;
            }
            .product {
                position: relative;
            }
            .product .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>');
            }
        </script>
        <?php
        if($mode === 'start')
            echo $jsHtml;
        ?>
    </head>
    <body style="font-family: sans-serif;">
        Режим: <a class="btn <?=$mode === 'start' ? 'active' : ''?>" href="./js_not_at_end.php">Подключение JavaScript в head</a> <a class="btn <?=$mode === 'end' ? 'active' : ''?>" href="./js_not_at_end.php?mode=end">Подключение JavaScript в конце страницы</a>
        <br />
        <p>Обратите внимание на разницу во времени загрузки изображения.</p>
        <div class="product">
            <img src="./photo.jpg?t=<?=microtime(true)?>" onload="endLoading(this)" />
        </div>
    </body>
    <?php
    if($mode === 'end')
        echo $jsHtml;
    ?>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .product img {
                max-width:100%;
            }
            .product {
                position: relative;
            }
            .product .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>');
            }
        </script>
        <script src="./10-kb-js.js?t=1772896904.1352.0"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.1"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.2"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.3"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.4"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.5"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.6"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.7"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.8"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.9"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.10"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.11"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.12"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.13"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.14"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.15"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.16"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.17"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.18"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.19"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.20"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.21"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.22"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.23"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.24"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.25"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.26"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.27"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.28"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.29"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.30"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.31"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.32"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.33"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.34"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.35"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.36"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.37"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.38"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.39"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.40"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.41"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.42"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.43"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.44"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.45"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.46"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.47"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.48"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.49"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.50"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.51"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.52"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.53"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.54"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.55"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.56"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.57"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.58"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.59"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.60"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.61"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.62"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.63"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.64"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.65"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.66"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.67"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.68"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.69"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.70"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.71"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.72"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.73"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.74"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.75"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.76"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.77"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.78"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.79"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.80"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.81"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.82"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.83"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.84"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.85"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.86"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.87"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.88"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.89"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.90"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.91"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.92"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.93"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.94"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.95"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.96"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.97"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.98"/></script>
<script src="./10-kb-js.js?t=1772896904.1353.99"/></script>
    </head>
    <body style="font-family: sans-serif;">
        Режим: <a class="btn active" href="./js_not_at_end.php">Подключение JavaScript в head</a> <a class="btn " href="./js_not_at_end.php?mode=end">Подключение JavaScript в конце страницы</a>
        <br />
        <p>Обратите внимание на разницу во времени загрузки изображения.</p>
        <div class="product">
            <img src="./photo.jpg?t=1772896904.1354" onload="endLoading(this)" />
        </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