You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tech-interview-handbook/front-end/performance.md

2.6 KiB

Performance

Glossary

  • Critical Rendering Path -
  • requestAnimationFrame

General Strategies

  1. Minimize Bytes.
  2. Reduce critical resources.
  3. Reduce CRP length. TODO: Explain what CRP length is.

Loading

  • Minify, Compress, Cache assets.
  • Browsers have a preloader to load assets ahead of time.

Rendering

  • Remove whitespace and comments from HTML/CSS/JS file via minification.
  • CSS
  • JavaScript
    • JS blocks HTML parsing. If the script is external, it will have to be downloaded first. This incurs latency in network and execution.
    • Shift <script> tags to the bottom.
    • Async:
      • Scripts that don't modify the DOM or CSSOM can use the async attribute to tell the browser not to block DOM parsing and does not need to wait for the CSSOM to be ready.
    • Defer JavaScript execution:
      • There is also a defer attribute available. The difference is that with defer, the script waits to execute until after the document has been parsed, whereas async lets the script run in the background while the document is being parsed.
    • Use web workers for long running operations to move into a web worker thread.
    • Use requestAnimationFrame
References

Measuring

  • Navigation Timing API is a JavaScript API for accurately measuring performance on the web. The API provides a simple way to get accurate and detailed timing statistics natively for page navigation and load events.
    • performance.timing: An object with the timestamps of the various events on the page. Some uses:
      • Network latency: responseEnd - fetchStart.
      • The time taken for page load once the page is received from the server: loadEventEnd - responseEnd.
      • The whole process of navigation and page load: loadEventEnd - navigationStart.

Tools

  • Yahoo YSlow
  • Google PageSpeed Insights
  • WebPageTest
  • Sitespeed.io
  • Google Lighthouse

Web Performance Rules