Design a JavaScript rendering diff: pre/post DOM, blocked resources, hydration timing.
- User
Design a JavaScript rendering diff: pre/post DOM, blocked resources, hydration timing.
Assistant
Design a JavaScript rendering diff: pre/post DOM, blocked resources, hydration timing.
The user is asking for a JavaScript rendering diff visualization - essentially a tool that shows the difference between pre-DOM and post-DOM states, blocked resources, and hydration timing. This is a performance analysis visualization.
Let me create an interactive, visually engaging single-file HTML page that simulates/visualizes:
I'll create an animated timeline visualization with:
Design approach:
Color scheme:
Let me build this:
This is a performance analysis tool that visualizes the rendering pipeline differences between pre-DOM and post-DOM states, identifies blocked resources, and tracks hydration timing.
Key Features:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rendering Diff Analyzer</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
background: #08090d;
color: #e8eaed;
min-height: 100vh;
overflow-x: hidden;
}
.background-grid {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
linear-gradient(rgba(0, 255, 200, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 255, 200, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
}
.container {
position: relative;
z-index: 1;
max-width: 1400px;
margin: 0 auto;
padding: 30px;
}
header {
text-align: center;
margin-bottom: 40px;
}
h1 {
font-size: 2.5rem;
font-weight: 300;
letter-spacing: 4px;
text-transform: uppercase;
background: linear-gradient(135deg, #00ffc8, #00a8ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
}
.subtitle {
color: #6b7280;
font-size: 0.9rem;
letter-spacing: 2px;
}
.metrics-bar {
display: flex;
justify-content: center;
gap: 40px;
margin-bottom: 40px;
flex-wrap: wrap;
}
.metric {
text-align: center;
padding: 20px 30px;
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 8px;
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
.metric:hover {
border-color: rgba(0, 255, 200, 0.3);
transform: translateY(-2px);
}
.metric::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent, var(--accent, #00ffc8), transparent);
}
.metric-value {
font-size: 2rem;
font-weight: 600;
color: var(--accent, #00ffc8);
}
.metric-label {
font-size: 0.75rem;
color: #9ca3af;
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 5px;
}
.timeline-section {
margin-bottom: 50px;
}
.section-title {
font-size: 1.1rem;
color: #9ca3af;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.section-title::before {
content: '';
width: 4px;
height: 20px;
background: #00ffc8;
border-radius: 2px;
}
.timeline {
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 12px;
padding: 30px;
position: relative;
}
.timeline-header {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.time-marker {
font-size: 0.75rem;
color: #6b7280;
}
.timeline-body {
position: relative;
min-height: 300px;
}
.timeline-track {
position: relative;
height: 40px;
margin-bottom: 8px;
display: flex;
align-items: center;
}
.track-label {
width: 160px;
font-size: 0.8rem;
color: #9ca3af;
padding-right: 15px;
text-align: right;
flex-shrink: 0;
}
.track-bar {
flex: 1;
height: 28px;
background: rgba(255, 255, 255, 0.02);
border-radius: 4px;
position: relative;
overflow: hidden;
}
.resource-block {
position: absolute;
height: 100%;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
padding: 0 10px;
font-size: 0.7rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.resource-block:hover {
transform: scaleY(1.2);
z-index: 10;
box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}
.resource-block.blocking {
background: linear-gradient(135deg, #ff6b35, #f7931e);
}
.resource-block.async {
background: linear-gradient(135deg, #00a8ff, #00ffc8);
}
.resource-block.defer {
background: linear-gradient(135deg, #8b5cf6, #a78bfa);
}
.resource-block.render-blocking {
background: repeating-linear-gradient(
45deg,
#ff6b35,
#ff6b35 5px,
#f7931e 5px,
#f7931e 10px
);
}
.blocking-indicator {
position: absolute;
top: -20px;
left: 0;
height: 4px;
background: #ff4444;
border-radius: 2px;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.diff-section {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 50px;
}
@media (max-width: 900px) {
.diff-section {
grid-template-columns: 1fr;
}
}
.diff-panel {
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 12px;
overflow: hidden;
}
.diff-panel-header {
padding: 15px 20px;
background: rgba(255, 255, 255, 0.02);
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
justify-content: space-between;
align-items: center;
}
.diff-panel-title {
font-weight: 500;
}
.diff-panel-badge {
font-size: 0.7rem;
padding: 4px 10px;
border-radius: 20px;
background: rgba(255, 255, 255, 0.1);
}
.diff-panel-badge.pre {
background: rgba(255, 107, 53, 0.2);
color: #ff6b35;
}
.diff-panel-badge.post {
background: rgba(0, 255, 200, 0.2);
color: #00ffc8;
}
.diff-content {
padding: 20px;
font-size: 0.85rem;
line-height: 1.8;
max-height: 300px;
overflow-y: auto;
}
.diff-content::-webkit-scrollbar {
width: 6px;
}
.diff-content::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.02);
}
.diff-content::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
}
.code-line {
display: flex;
align-items: flex-start;
gap: 15px;
opacity: 0;
transform: translateX(-10px);
animation: slideIn 0.3s ease forwards;
}
@keyframes slideIn {
to {
opacity: 1;
transform: translateX(0);
}
}
.line-number {
color: #4b5563;
min-width: 30px;
text-align: right;
user-select: none;
}
.line-content {
flex: 1;
}
.line-added {
background: rgba(0, 255, 200, 0.1);
margin: 0 -20px;
padding: 0 20px;
border-left: 3px solid #00ffc8;
}
.line-removed {
background: rgba(255, 68, 68, 0.1);
margin: 0 -20px;
padding: 0 20px;
border-left: 3px solid #ff4444;
}
.line-modified {
background: rgba(255, 193, 7, 0.1);
margin: 0 -20px;
padding: 0 20px;
border-left: 3px solid #ffc107;
}
.tag { color: #ff79c6; }
.attr { color: #50fa7b; }
.value { color: #f1fa8c; }
.comment { color: #6272a4; }
.hydration-section {
margin-bottom: 50px;
}
.hydration-timeline {
display: flex;
align-items: center;
gap: 0;
padding: 30px;
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 12px;
position: relative;
}
.hydration-phase {
flex: 1;
text-align: center;
position: relative;
padding: 20px 10px;
opacity: 0;
animation: fadeInUp 0.5s ease forwards;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.hydration-phase::after {
content: '';
position: absolute;
top: 50%;
right: -50%;
width: 100%;
height: 2px;
background: linear-gradient(90deg, var(--phase-color), transparent);
transform: translateY(-50%);
}
.hydration-phase:last-child::after {
display: none;
}
.phase-icon {
width: 50px;
height: 50px;
border-radius: 50%;
margin: 0 auto 15px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
background: rgba(255, 255, 255, 0.05);
border: 2px solid var(--phase-color);
position: relative;
}
.phase-icon::before {
content: '';
position: absolute;
inset: -5px;
border-radius: 50%;
border: 1px solid var(--phase-color);
opacity: 0.3;
animation: ripple 2s infinite;
}
@keyframes ripple {
0% { transform: scale(1); opacity: 0.3; }
100% { transform: scale(1.5); opacity: 0; }
}
.phase-name {
font-weight: 500;
margin-bottom: 5px;
}
.phase-time {
font-size: 0.8rem;
color: var(--phase-color);
}
.phase-status {
font-size: 0.7rem;
color: #6b7280;
margin-top: 5px;
}
.tooltip {
position: fixed;
background: #1a1a2e;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 15px;
font-size: 0.8rem;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease;
z-index: 1000;
max-width: 300px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.tooltip.active {
opacity: 1;
}
.tooltip-title {
font-weight: 600;
margin-bottom: 10px;
color: #fff;
}
.tooltip-row {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: #9ca3af;
}
.tooltip-value {
color: #00ffc8;
margin-left: 20px;
}
.legend {
display: flex;
justify-content: center;
gap: 30px;
margin-top: 20px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.8rem;
color: #9ca3af;
}
.legend-color {
width: 16px;
height: 16px;
border-radius: 4px;
}
.progress-indicator {
position: fixed;
top: 0;
left: 0;
height: 3px;
background: linear-gradient(90deg, #00ffc8, #00a8ff);
z-index: 1000;
transition: width 0.3s ease;
}
.control-bar {
display: flex;
justify-content: center;
gap: 15px;
margin-bottom: 30px;
}
.control-btn {
padding: 10px 25px;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
color: #e8eaed;
font-family: inherit;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
}
.control-btn:hover {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(0, 255, 200, 0.3);
}
.control-btn.active {
background: rgba(0, 255, 200, 0.1);
border-color: #00ffc8;
color: #00ffc8;
}
.waterfall-marker {
position: absolute;
top: 0;
width: 1px;
height: 100%;
background: rgba(255, 255, 255, 0.1);
z-index: 5;
}
.waterfall-marker.fcp {
background: #00ffc8;
}
.waterfall-marker.lcp {
background: #00a8ff;
}
.waterfall-marker.tti {
background: #8b5cf6;
}
.marker-label {
position: absolute;
top: -25px;
left: 50%;
transform: translateX(-50%);
font-size: 0.65rem;
color: #9ca3af;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="background-grid"></div>
<div class="progress-indicator" id="progressIndicator"></div>
<div class="container">
<header>
<h1>Rendering Diff Analyzer</h1>
<p class="subtitle">Pre/Post DOM Visualization | Resource Blocking | Hydration Metrics</p>
</header>
<div class="metrics-bar">
<div class="metric" style="--accent: #ff6b35">
<div class="metric-value" id="blockTime">0ms</div>
<div class="metric-label">Total Blocking Time</div>
</div>
<div class="metric" style="--accent: #00ffc8">
<div class="metric-value" id="fcpTime">0ms</div>
<div class="metric-label">First Contentful Paint</div>
</div>
<div class="metric" style="--accent: #00a8ff">
<div class="metric-value" id="lcpTime">0ms</div>
<div class="metric-label">Largest Contentful Paint</div>
</div>
<div class="metric" style="--accent: #8b5cf6">
<div class="metric-value" id="ttiTime">0ms</div>
<div class="metric-label">Time to Interactive</div>
</div>
<div class="metric" style="--accent: #f59e0b">
<div class="metric-value" id="hydrateTime">0ms</div>
<div class="metric-label">Hydration Duration</div>
</div>
</div>
<div class="control-bar">
<button class="control-btn active" data-filter="all">All Resources</button>
<button class="control-btn" data-filter="blocking">Blocking Only</button>
<button class="control-btn" data-filter="async">Async/Defer</button>
<button class="control-btn" id="replayBtn">Replay Animation</button>
</div>
<div class="timeline-section">
<div class="section-title">Resource Loading Waterfall</div>
<div class="timeline">
<div class="timeline-header">
<div class="time-marker" style="width: 160px; text-align: right; padding-right: 15px;">Resource</div>
<div class="time-marker">0ms</div>
<div class="time-marker">500ms</div>
<div class="time-marker">1000ms</div>
<div class="time-marker">1500ms</div>
<div class="time-marker">2000ms</div>
</div>
<div class="timeline-body" id="waterfall">
<!-- Populated by JS -->
</div>
</div>
</div>
<div class="diff-section">
<div class="diff-panel">
<div class="diff-panel-header">
<span class="diff-panel-title">Pre-DOM State</span>
<span class="diff-panel-badge pre">Initial HTML</span>
</div>
<div class="diff-content" id="preDom">
<!-- Populated by JS -->
</div>
</div>
<div class="diff-panel">
<div class="diff-panel-header">
<span class="diff-panel-title">Post-DOM State</span>
<span class="diff-panel-badge post">After Hydration</span>
</div>
<div class="diff-content" id="postDom">
<!-- Populated by JS -->
</div>
</div>
</div>
<div class="hydration-section">
<div class="section-title">Hydration Timeline</div>
<div class="hydration-timeline" id="hydrationTimeline">
<!-- Populated by JS -->
</div>
</div>
<div class="legend">
<div class="legend-item">
<div class="legend-color" style="background: linear-gradient(135deg, #ff6b35, #f7931e);"></div>
<span>Render Blocking</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background: linear-gradient(135deg, #00a8ff, #00ffc8);"></div>
<span>Async Script</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background: linear-gradient(135deg, #8b5cf6, #a78bfa);"></div>
<span>Deferred Script</span>
</div>
<div class="legend-item">
<div class="legend-color" style="background: repeating-linear-gradient(45deg, #ff6b35, #ff6b35 5px, #f7931e 5px, #f7931e 10px);"></div>
<span>Critical Blocking</span>
</div>
</div>
</div>
<div class="tooltip" id="tooltip">
<div class="tooltip-title"></div>
<div class="tooltip-content"></div>
</div>
<script>
// Resource data
const resources = [
{ name: 'index.html', type: 'document', start: 0, duration: 120, blocking: true, category: 'blocking' },
{ name: 'critical.css', type: 'stylesheet', start: 50, duration: 180, blocking: true, category: 'blocking' },
{ name: 'app.js', type: 'script', start: 80, duration: 450, blocking: true, category: 'blocking' },
{ name: 'analytics.js', type: 'script', start: 200, duration: 320, blocking: false, async: true, category: 'async' },
{ name: 'vendor.js', type: 'script', start: 230, duration: 580, blocking: false, defer: true, category: 'defer' },
{ name: 'styles.css', type: 'stylesheet', start: 150, duration: 210, blocking: true, category: 'blocking' },
{ name: 'chunk-1.js', type: 'script', start: 550, duration: 280, blocking: false, defer: true, category: 'defer' },
{ name: 'hydrate.js', type: 'script', start: 600, duration: 150, blocking: false, async: true, category: 'async' },
{ name: 'fonts.woff2', type: 'font', start: 100, duration: 400, blocking: true, category: 'blocking' },
{ name: 'hero.webp', type: 'image', start: 180, duration: 350, blocking: false, category: 'async' },
];
// Pre/Post DOM diff data
const preDomLines = [
{ content: '<span class="comment"><!-- Server Rendered HTML --></span>' },
{ content: '<span class="tag"><div</span> <span class="attr">id</span>=<span class="value">"app"</span><span class="tag">></span>' },
{ content: ' <span class="tag"><header</span> <span class="attr">class</span>=<span class="value">"static"</span><span class="tag">></span>', modified: true },
{ content: ' <span class="tag"><nav></span>...<span class="tag"></nav></span>' },
{ content: ' <span class="tag"></header></span>' },
{ content: ' <span class="tag"><main></span>' },
{ content: ' <span class="tag"><div</span> <span class="attr">data-static</span>=<span class="value">"true"</span><span class="tag">></span>', removed: true },
{ content: ' Loading...', removed: true },
{ content: ' <span class="tag"></div></span>', removed: true },
{ content: ' <span class="tag"></main></span>' },
{ content: '<span class="tag"></div></span>' },
];
const postDomLines = [
{ content: '<span class="comment"><!-- After Client Hydration --></span>' },
{ content: '<span class="tag"><div</span> <span class="attr">id</span>=<span class="value">"app"</span> <span class="attr">data-hydrated</span>=<span class="value">"true"</span><span class="tag">></span>', added: true },
{ content: ' <span class="tag"><header</span> <span class="attr">class</span>=<span class="value">"interactive"</span><span class="tag">></span>', modified: true },
{ content: ' <span class="tag"><nav</span> <span class="attr">data-reactid</span>=<span class="value">"0.1"</span><span class="tag">></span>', added: true },
{ content: ' <span class="tag"><button</span> <span class="attr">onClick</span>=<span class="value">{handler}</span><span class="tag">></span>', added: true },
{ content: ' <span class="tag"></nav></span>' },
{ content: ' <span class="tag"></header></span>' },
{ content: ' <span class="tag"><main></span>' },
{ content: ' <span class="tag"><div</span> <span class="attr">data-component</span>=<span class="value">"Hero"</span><span class="tag">></span>', added: true },
{ content: ' <span class="tag"><h1></span>Interactive Content<span class="tag"></h1></span>', added: true },
{ content: ' <span class="tag"></div></span>' },
{ content: ' <span class="tag"></main></span>' },
{ content: '<span class="tag"></div></span>' },
];
// Hydration phases
const hydrationPhases = [
{ name: 'Boot', time: '45ms', status: 'JS Bundle Load', color: '#ff6b35', icon: '1' },
{ name: 'Parse', time: '120ms', status: 'AST Generation', color: '#f7931e', icon: '2' },
{ name: 'Eval', time: '180ms', status: 'Script Execution', color: '#ffc107', icon: '3' },
{ name: 'Reconcile', time: '85ms', status: 'VDOM Diff', color: '#00ffc8', icon: '4' },
{ name: 'Commit', time: '65ms', status: 'DOM Updates', color: '#00a8ff', icon: '5' },
{ name: 'Interactive', time: '0ms', status: 'Event Bindings', color: '#8b5cf6', icon: '6' },
];
// Metrics
const metrics = {
blockTime: 847,
fcpTime: 423,
lcpTime: 892,
ttiTime: 1240,
hydrateTime: 495
};
// Initialize
function init() {
renderWaterfall();
renderDiffPanels();
renderHydrationTimeline();
animateMetrics();
setupEventListeners();
animateProgress();
}
function renderWaterfall(filter = 'all') {
const container = document.getElementById('waterfall');
container.innerHTML = '';
const totalDuration = 2000;
const labelWidth = 160;
// Add core web vitals markers
const markers = [
{ time: metrics.fcpTime, class: 'fcp', label: 'FCP' },
{ time: metrics.lcpTime, class: 'lcp', label: 'LCP' },
{ time: metrics.ttiTime, class: 'tti', label: 'TTI' }
];
const filteredResources = filter === 'all'
? resources
: resources.filter(r => r.category === filter);
filteredResources.forEach((resource, index) => {
const track = document.createElement('div');
track.className = 'timeline-track';
track.style.opacity = '0';
track.style.animation = `slideIn 0.3s ease forwards ${index * 0.1}s`;
const label = document.createElement('div');
label.className = 'track-label';
label.textContent = resource.name;
const bar = document.createElement('div');
bar.className = 'track-bar';
// Add markers
markers.forEach(marker => {
const markerEl = document.createElement('div');
markerEl.className = `waterfall-marker ${marker.class}`;
markerEl.style.left = `${(marker.time / totalDuration) * 100}%`;
const labelEl = document.createElement('div');
labelEl.className = 'marker-label';
labelEl.textContent = marker.label;
markerEl.appendChild(labelEl);
bar.appendChild(markerEl);
});
const block = document.createElement('div');
block.className = 'resource-block';
if (resource.blocking) {
block.classList.add('blocking');
if (resource.type === 'stylesheet') {
block.classList.add('render-blocking');
}
} else if (resource.async) {
block.classList.add('async');
} else if (resource.defer) {
block.classList.add('defer');
}
const startPercent = (resource.start / totalDuration) * 100;
const widthPercent = (resource.duration / totalDuration) * 100;
block.style.left = `${startPercent}%`;
block.style.width = `${Math.max(widthPercent, 2)}%`;
block.textContent = resource.duration + 'ms';
block.style.animationDelay = `${index * 0.1 + 0.2}s`;
block.style.opacity = '0';
block.style.animation = `slideIn 0.3s ease forwards ${index * 0.1 + 0.2}s`;
block.addEventListener('mouseenter', (e) => showTooltip(e, resource));
block.addEventListener('mouseleave', hideTooltip);
bar.appendChild(block);
track.appendChild(label);
track.appendChild(bar);
container.appendChild(track);
});
}
function renderDiffPanels() {
const preContainer = document.getElementById('preDom');
const postContainer = document.getElementById('postDom');
preDomLines.forEach((line, index) => {
const lineEl = createCodeLine(line, index);
preContainer.appendChild(lineEl);
});
postDomLines.forEach((line, index) => {
const lineEl = createCodeLine(line, index);
postContainer.appendChild(lineEl);
});
}
function createCodeLine(line, index) {
const div = document.createElement('div');
div.className = 'code-line';
div.style.animationDelay = `${index * 0.05}s`;
let lineClass = '';
if (line.added) lineClass = 'line-added';
else if (line.removed) lineClass = 'line-removed';
else if (line.modified) lineClass = 'line-modified';
div.innerHTML = `
<span class="line-number">${index + 1}</span>
<span class="line-content ${lineClass}">${line.content}</span>
`;
return div;
}
function renderHydrationTimeline() {
const container = document.getElementById('hydrationTimeline');
container.innerHTML = '';
hydrationPhases.forEach((phase, index) => {
const div = document.createElement('div');
div.className = 'hydration-phase';
div.style.setProperty('--phase-color', phase.color);
div.style.animationDelay = `${index * 0.15}s`;
div.innerHTML = `
<div class="phase-icon" style="border-color: ${phase.color}">${phase.icon}</div>
<div class="phase-name">${phase.name}</div>
<div class="phase-time" style="color: ${phase.color}">${phase.time}</div>
<div class="phase-status">${phase.status}</div>
`;
container.appendChild(div);
});
}
function animateMetrics() {
Object.keys(metrics).forEach((key, index) => {
const element = document.getElementById(key);
const target = metrics[key];
animateNumber(element, target, index * 100);
});
}
function animateNumber(element, target, delay) {
setTimeout(() => {
let current = 0;
const increment = target / 30;
const interval = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(interval);
}
element.textContent = Math.round(current) + 'ms';
}, 20);
}, delay);
}
function animateProgress() {
const indicator = document.getElementById('progressIndicator');
let width = 0;
const interval = setInterval(() => {
width += 2;
indicator.style.width = width + '%';
if (width >= 100) {
clearInterval(interval);
setTimeout(() => {
indicator.style.opacity = '0';
}, 500);
}
}, 30);
}
function showTooltip(e, resource) {
const tooltip = document.getElementById('tooltip');
const titleEl = tooltip.querySelector('.tooltip-title');
const contentEl = tooltip.querySelector('.tooltip-content');
titleEl.textContent = resource.name;
contentEl.innerHTML = `
<div class="tooltip-row">
<span>Type:</span>
<span class="tooltip-value">${resource.type}</span>
</div>
<div class="tooltip-row">
<span>Start:</span>
<span class="tooltip-value">${resource.start}ms</span>
</div>
<div class="tooltip-row">
<span>Duration:</span>
<span class="tooltip-value">${resource.duration}ms</span>
</div>
<div class="tooltip-row">
<span>Blocking:</span>
<span class="tooltip-value" style="color: ${resource.blocking ? '#ff6b35' : '#00ffc8'}">${resource.blocking ? 'Yes' : 'No'}</span>
</div>
<div class="tooltip-row">
<span>Load Strategy:</span>
<span class="tooltip-value">${resource.async ? 'Async' : resource.defer ? 'Defer' : 'Sync'}</span>
</div>
`;
tooltip.style.left = e.pageX + 15 + 'px';
tooltip.style.top = e.pageY + 15 + 'px';
tooltip.classList.add('active');
}
function hideTooltip() {
document.getElementById('tooltip').classList.remove('active');
}
function setupEventListeners() {
// Filter buttons
document.querySelectorAll('.control-btn[data-filter]').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.control-btn[data-filter]').forEach(b => b.classList.remove('active'));
e.target.classList.add('active');
renderWaterfall(e.target.dataset.filter);
});
});
// Replay button
document.getElementById('replayBtn').addEventListener('click', () => {
const indicator = document.getElementById('progressIndicator');
indicator.style.opacity = '1';
indicator.style.width = '0%';
document.getElementById('waterfall').innerHTML = '';
document.getElementById('preDom').innerHTML = '';
document.getElementById('postDom').innerHTML = '';
document.getElementById('hydrationTimeline').innerHTML = '';
setTimeout(() => {
renderWaterfall();
renderDiffPanels();
renderHydrationTimeline();
animateMetrics();
animateProgress();
}, 100);
});
// Mouse move for tooltip
document.addEventListener('mousemove', (e) => {
const tooltip = document.getElementById('tooltip');
if (tooltip.classList.contains('active')) {
tooltip.style.left = e.pageX + 15 + 'px';
tooltip.style.top = e.pageY + 15 + 'px';
}
});
}
// Start
init();
</script>
</body>
</html>
1. Resource Waterfall Timeline:
2. Pre/Post DOM Diff:
3. Hydration Phases:
4. Interactive Features: