← Back to gallery
The Flash poster

Project walkthrough

The Flash

Explore the concept, hints, and starter code for this Nic Cage inspired build.

Title: Speed Force Metrics with The Flash and Performance API

Description:

Inspired by the high-speed and action-packed adventures of The Flash, this project uses the Performance API to create a web application that monitors and displays various performance metrics in real-time. The application captures the fast-paced and dynamic nature of the film, enabling users to gain insights into the performance of their web pages. This project demonstrates the practical use of the Performance API to measure and improve web performance, reflecting the film’s emphasis on speed and efficiency.

Features:

  • Real-Time Performance Monitoring: Use the Performance API to track key performance metrics such as page load time, resource load times, and navigation timings.
  • Dynamic Display: Provide a real-time dashboard to display performance metrics.
  • Thematic Design: Reflect the fast-paced and dynamic atmosphere of The Flash through the application’s design and interactions.

Starting Code:

Beginner Hints:

  • Create a single index.html file.
  • Copy the full HTML code block into that file.
  • Open index.html in your browser. If something doesn’t work, try a local server like python -m http.server.
  • Open DevTools Console to spot errors and typos quickly.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Speed Force Metrics with The Flash and Performance API</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #121212;
        color: #f0f0f0;
        text-align: center;
        padding: 50px;
    }
    .container {
        max-width: 800px;
        margin: 0 auto;
        padding: 20px;
        background-color: #1f1f1f;
        border: 1px solid #333;
        border-radius: 10px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    }
    h1 {
        margin-bottom: 20px;
        color: #e84545;
    }
    .metric {
        margin: 20px 0;
        padding: 10px;
        border: 1px solid #555;
        border-radius: 5px;
        background-color: #2e2e2e;
    }
    .metric h2 {
        margin: 0;
        font-size: 1.2em;
        color: #e84545;
    }
    .metric p {
        margin: 5px 0 0;
    }
</style>
</head>
<body>
    <div class="container">
        <h1>Speed Force Metrics</h1>
        <p>Monitor web performance inspired by The Flash.</p>

        <div class="metric">
            <h2>Page Load Time</h2>
            <p id="loadTime">Calculating...</p>
        </div>
        <div class="metric">
            <h2>Resource Load Times</h2>
            <ul id="resourceLoadTimes">Calculating...</ul>
        </div>
        <div class="metric">
            <h2>Navigation Timings</h2>
            <p id="navigationTimings">Calculating...</p>
        </div>
    </div>
<script>
    function displayLoadTime() {
        const loadTime = window.performance.timing.loadEventEnd - window.performance.timing.navigationStart;
        document.getElementById('loadTime').textContent = `${loadTime} ms`;
    }

    function displayResourceLoadTimes() {
        const resources = window.performance.getEntriesByType('resource');
        const resourceLoadTimesList = document.getElementById('resourceLoadTimes');
        resourceLoadTimesList.innerHTML = '';
        resources.forEach(resource => {
            const listItem = document.createElement('li');
            listItem.textContent = `${resource.name}: ${resource.duration.toFixed(2)} ms`;
            resourceLoadTimesList.appendChild(listItem);
        });
    }

    function displayNavigationTimings() {
        const navigation = window.performance.getEntriesByType('navigation')[0];
        const navigationTimings = document.getElementById('navigationTimings');
        if (navigation) {
            navigationTimings.innerHTML = `
                <p>Redirect Time: ${navigation.redirectEnd - navigation.redirectStart} ms</p>
                <p>App Cache Time: ${navigation.domainLookupStart - navigation.fetchStart} ms</p>
                <p>DNS Lookup Time: ${navigation.domainLookupEnd - navigation.domainLookupStart} ms</p>
                <p>TCP Handshake Time: ${navigation.connectEnd - navigation.connectStart} ms</p>
                <p>Response Time: ${navigation.responseEnd - navigation.requestStart} ms</p>
                <p>DOM Processing Time: ${navigation.domComplete - navigation.domLoading} ms</p>
                <p>Load Event Time: ${navigation.loadEventEnd - navigation.loadEventStart} ms</p>
            `;
        } else {
            navigationTimings.textContent = 'Navigation timing data not available.';
        }
    }

    window.addEventListener('load', () => {
        displayLoadTime();
        displayResourceLoadTimes();
        displayNavigationTimings();
    });
</script>
</body>
</html>

References:

Project Overview:

This project captures the fast-paced and dynamic atmosphere of The Flash using the Performance API to monitor and display web performance metrics in real-time. Users can gain insights into page load times, resource load times, and navigation timings, providing an engaging and informative experience. The application demonstrates the practical use of the Performance API for measuring and improving web performance, reflecting the film’s themes of speed and efficiency. Embrace the agility and speed of The Flash to master the use of the Performance API in web development. Praise Cage!