I have a page where it has to load 3 files of javascript (which is quite big) before all the page element become accesible. If one of the link is clicked then the load stops and whole page will not load the script right.
I make a solution by masking the page with an overlay which makes the page black before all of it was loaded. So on top of my page I put
$(".black-overlay").show();
which is a div that mask my entire page with z-index of 9999. Then after the page was loaded, I put
$(function() {
$(".black-overlay").hide();
});
which from sources I read is the same as document ready function, so the overlay dissappears after the page load.
My problem is, this only works sometimes. One case the overlay gone but the link is still broken (means the script is not loaded yet). Another case is sometimes the overlay will not show if: I move to another page, then back to the main page, at the main page the overlay must've shown again since the script must've loaded again. But sometimes, it works just fine.
Is there any cleaner solution to this problem?
[EDIT] This happens especially if the internet connection to the website is very slow.