I have already created this in the following way. In the page header, I put all the CSS and jQuery files and in the page footer before closing the body
tag I add the rest of the scripts and an embedded script, as in the example:
<html>
<head>
<meta charset="UTF-8">
<title>Exemplo</title>
<link rel="stylesheet" type="text/css" href="./css/estilos.css">
<link rel="stylesheet" type="text/css" href="./css/estilos1.css">
<link rel="stylesheet" type="text/css" href="./css/estilos2.css">
<link rel="stylesheet" type="text/css" href="./css/estilos3.css">
<script type="text/javascript" src="./js/jquery.min.js"></script>
</head>
<body>
<div id="loading"><img src="./img/loading.gif" alt="Carregando..."></div>
<div id="conteudo">
<!-- Restante do conteúdo da página -->
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#loading').hide('fade');
});
</script>
<script type="text/javascript" src="./js/script1.js"></script>
<script type="text/javascript" src="./js/script2.js"></script>
<script type="text/javascript" src="./js/script3.js"></script>
<script type="text/javascript" src="./js/script4.js"></script>
<script type="text/javascript" src="./js/script5.js"></script>
</body>
</html>
The example shown works as follows:
Files referenced by CSS and jQuery are loaded
When the browser starts rendering the page, the div#loading
element is the first one to be created.
It should contain a CSS class that stays on the rest of the page, such as position:fixed; z-index: 10000;
or another to your liking. While the page is being mounted it is being displayed.
When the browser finishes rendering the page, the onload
event takes effect and the jQuery(document).ready(...)
method is executed, and within that method we hide the div#loading
This would be the closest to a "real load". Another way would be to load only the javascript responsible for this "loading" and another to fetch the rest of the page via AJAX as in @Marcio's response, this would be a little closer to the "real load" but a bit more laborious, since it would have to worry a lot about what you need to look for.