How to resolve loading part of the page in delay

Asked

Viewed 448 times

2

The pages of a project I have are having a strange behavior, when being called an excerpt of the page is being loaded, apparently, late, the code is this:

  <div class="page-banner no-subtitle">
<div class="container">
  <div class="row">
    <div class="col-md-6">
      <h2>PRODUTOS</h2>
    </div>
    <div class="col-md-6">
      <ul class="breadcrumbs">
        <li><a href="index.php">Início</a></li>
        <li>Produtos</li>
      </ul>
    </div>
  </div>
</div>

Right at the top of the page I have this:

<div class="hidden-header"></div>

And to him is associated a .js, which is this:

var headerEle = function(){
    var $headerHeight = $('header').height();
    $('.hidden-header').css({ 'height' : $headerHeight  + "px" });
};

$(window).load(function () {
  headerEle();
});

$(window).resize(function () {
   headerEle();
});

The page is delayed in loading, I tried some options and nothing took effect, if I withdraw or comment on the code .js the page-banner some.

An example of behavior can be seen here

2 answers

2


I took a look at your code:

  • Place all Javascript at the bottom of the page before closing tags of </body>. Doing so implies that Javasccript has to wait for the DOM to fully load so it can, yes, execute.
  • I saw that you have a <div></div> of pre-loading the page, the one that keeps rotating a loader. Use it as follows to your advantage:

$(window).on('load', function () {
    $("#loader").hide("slow");
});

By doing this, you force <div></div> Loader run on screen until the entire document is loaded.

  • Hello @Eduardo Almeida, thanks for the tip, I did the recommended and the problem still persists.

  • Correct me if I’m wrong, but some parts of the page are called through PHP with require, require_once, include or include_once, right?

  • Hello @Eduardo Almeida, the content . php is called by require_once.

1

The Loader solution is good, but I doubt that such a small JS will delay page loading.

Ideally, you should first find out what is slowing down page loading, before deciding what to do to fix it.

Using Chrome (or Firefox) press < Ctrl >+< shift >+< i >. Click on the "Network" option (or Network, depending on the language) and reload your page.

You’ll be able to see graphically what’s holding this shipment. Once knowing this it will be easier to give some hint of what can be done to improve performance.

  • Thanks for the excellent tip @Rhubenni Telesco, I’ll start doing it right now, once again thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.