Calculate the time it takes to render a critical process

Source: Internet
Author: User

You can't optimize things that you can't measure. But the Navegation Timing API allows us to measure the critical rendering process time!

    • Navigation Timing provides a high-precision timestamp for the calculation of CRP
    • The browser sends a series of measurable times to capture the various states of CRP

The Navigation Timing API provides a good measurement:

Each label in the table above corresponds to a high-precision timestamp that the browser monitors when each page is loaded. We remove everything and network-related timestamps, showing only a few:

      • domLoading: This is the timestamp at the beginning of the entire process, when the browser first receives the bytes of the HTML document when the parsing time begins.
      • domInteractive: The timestamp when the browser completed all HTML parsing and the DOM construct was completed.


      : When Dom is finished and no CSS style prevents JS from executing-it means that we can now construct the timestamp of the render tree--.
      • Many JS frameworks wait for this event before they begin to execute their own logic-because the browser captures Eventstart and eventend timestamps to allow us to track how long this event executes.
    • domComplete: As the name implies, all the resources on the page (such as samples, etc.) are downloaded and all the actions on the page are finished
    • loadEvent: Additional application logic is triggered when the OnLoad event is started when the browser is loaded in the last step on each page
      • domInteractiveMark Dom Complete


      marking the completion of the DOM and Cssom
      • If there is no JS blocking, then dominteractive will be domcontentloaded immediately.
    • domCompleteMark when the page and all the resources are complete

<HTML>  <Head>    <title>Critical path:measure</title>    <Metaname= "Viewport"content= "Width=device-width,initial-scale=1">    <Linkhref= "Style.css"rel= "stylesheet">    <Script>      functionMEASURECRP () {varT=window.performance.timing, interactive=t.dominteractive-t.domloading, DCL=T.domcontentloadedeventstart-t.domloading, complete=T.domcomplete-t.domloading; varStats=Document.createelement ('P'); Stats.textcontent= 'Interactive:' +Interactive+ 'MS,' +            'DCL:' +DCL+ 'MS, complete:' + Complete+ 'Ms';      Document.body.appendChild (stats); }    </Script>  </Head>  <Bodyonload= "MEASURECRP ()">    <P>Hello<span>Web Performance</span>students!</P>    <Div><imgsrc= "Awesome-photo.jpg"></Div>  </Body></HTML>

The code above is: the Navigation Timing API captures all relevant timestamps and our code waits for the OnLoad event to trigger-remember that the OnLoad event is in Dominteractive, Domcontentloaded and Domcomplete are triggered after--and each timestamp is calculated differently.

Just like what we say and do, I can use a function to simply trace all of these processes.

You can also embed the code of the analytics provider (Google Analytics does this automatically) in your code.

Original link:

Calculate the time it takes to render a critical process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.