Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent gradually showing a page?

My site loads images very slowly. Some text appears, then some tables, then some images... and then - body background image.
How can I force that nothing should be displayed till whole the page is ready ?

like image 398
Bonaca Avatar asked Dec 18 '12 21:12

Bonaca


People also ask

What causes website to load slowly?

Slow site speeds can result from network congestion, bandwidth throttling and restrictions, data discrimination and filtering, or content filtering. If you notice slow speeds when visiting your site, you can run a traceroute between your computer and your website to test the connection.

How would you respond to a customer who claims their website is loading too slowly?

Sending the email to the customer. Once you understand the issues that were causing the website to be slow and you've addressed them, you can respond to your customer with an email explaining your findings and suggestions on further actions.

How do I reduce DOM Content Loaded time?

To speed up DomContentLoaded , you can do a few things: Make script tags async where possible. Moving script tags to the end of the document doesn't help speed up DomContentLoaded , as the browser must still evaluate the Javascript before completing the construction of the DOM.


2 Answers

You could add a class at the body which has display:none and remove it once the page is loaded..

<body class="loading">
...
</body>

and

<script>
    window.onload = function(){document.body.className = '';};
</script>
like image 58
Gabriele Petrioli Avatar answered Oct 02 '22 11:10

Gabriele Petrioli


Probably the easiest / best way would be to use Javascript to do this. The main way I have seen this implemented is the document ready handler revealing all the hidden stuff.

$(document).ready(function() { $('*').show(); });  // Or something similar.

Of course, people like to see some sort of feedback of "progress" so your site doesn't appear poorly coded or as if the server is junk. So a loader bar or whatever.

As I mentioned above, the best place for these types of questions is Stack Overflow, and perhaps this will be moved over there by a higher-ranked individual. In the mean time, here is a very similar question on Stack Overflow.

like image 25
nerdwaller Avatar answered Oct 02 '22 11:10

nerdwaller