curriculum/challenges/english/blocks/review-web-performance/6724e18296fa40173cc2437c.md
Some best practices for source order include:
Here is an example of good source order, using the best practices we just went through:
<h1>Welcome to FastSite!</h1>
<p>Critical information loads first.</p>
<script src="slow-script.js" defer></script>
Some ways of reducing latency include:
Here are some ways to improve INP:
requestIdleCallback() for non-critical scripts. This will queue a function to be called during a browser's idle periods.performance.now(): This API gives you high-precision timestamps (in milliseconds) to measure how long different parts of your site take to load.const start = performance.now();
// Run some code here
const end = performance.now();
console.log(`Execution time: ${end - start}ms`);
DOMContentLoaded.const timing = performance.timing;
const pageLoadTime = timing.loadEventEnd - timing.navigationStart;
console.log(`Page load time: ${pageLoadTime}ms`);
PerformanceObserver: This API listens for performance events such as layout shifts, long tasks, and user interactions.const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(`Long task detected: ${entry.duration}ms`);
});
});
observer.observe({ type: "longtask", buffered: true });
Review the Web Performance topics and concepts.