Before someone throws me around the neck I have to say that I know that PHP
is loaded on the server and builds the page, that after this the client loads the resulting HTML
with its JavaScript
and its events.
Having said that, I would like to know if there is any method to load JavaScript
before PHP
.
This idea comes from the following problem. I have a script
that shows the typical "Loading ..." dialog. When queries PHP
are not very heavy it does not take long to be shown while the HTML
is loaded.
This would be the structure of script
:
<html>
<head>
<script>
waitingDialog.show('CARGANDO...', {dialogSize: 'sm', progressType: 'warning'});
</script>
</head>
<?php
//AQUI IRIA EL PHP COMPLETO
?>
<body>
....
</body>
<script>
$(document).ready(function() {
waitingDialog.hide();
});
</script>
</html>
In the case of having a% heavy%, the page remains loading a good time but does not show the loading message, because as mentioned at the beginning PHP
load before PHP
.
As you can see a minute of waiting can be very heavy for the user and even more if you do not have any message that the page is loading.
I have researched a bit and most say that loading JavaScript
before JavaScript
is impossible, but maybe there is some way to load the page in a structured way leaving the heavier for the end (I do not know if it is possible or not).
Note: As an alternative solution, we have considered looking for a PHP
plugin
that shows this dialog. So I also accept answers with the use of other plugins.