What are alternative methods to using PHP includes for dynamic menus to avoid visual disturbances on a webpage?

When using PHP includes for dynamic menus on a webpage, the issue of visual disturbances can arise when the menu content is loaded separately from the rest of the page, causing a delay in rendering. One alternative method to avoid this issue is to use AJAX to dynamically load the menu content after the initial page load, ensuring a smoother user experience.

<!-- HTML code for the menu container -->
<div id="menu"></div>

<!-- JavaScript code to load menu content using AJAX -->
<script>
    window.onload = function() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("menu").innerHTML = this.responseText;
            }
        };
        xhttp.open("GET", "menu.php", true);
        xhttp.send();
    };
</script>