Hide page until everything is loaded Advanced

前端 未结 8 1633
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 04:10

I have a webpage which heavily makes use of jQuery.

My goal is to only show the page when everything is ready.

With that I want to avoid showing the annoying

8条回答
  •  清歌不尽
    2020-12-13 04:39

    If you have a div #bodyholder then you can put display:none in your CSS for it and then with jQuery do:

    $(document).ready(function() {
         $('#body_holder').show();
    });
    

    I don't see why hiding a div should interfere with the loading of anything, because all it means is it is hidden. However, if you have lots of jQuery being used then make sure you wrap it in $(document).ready which will make sure that the DOM is fully loaded before the Javascript is executed

    A further point is that HTML/CSS is designed for progressive loading, and if you do it properly then you can get a nice progressive loading of content for your users. I personally wouldn't want my users getting a white screen for a few seconds until everything was loaded. Move your Javascript to the end of the page so that it doesn't block loading and get content onto the screen as quickly as possible.

提交回复
热议问题