Add Export APIs & Optimization Checks (Phases 14-15)

Features Added:
- HAR file export endpoint (/api/export/:testId/har)
- CSV metrics export endpoint (/api/export/:testId/csv)
- Optimization checker analyzing 8 categories:
  * Image optimization
  * Text compression (gzip/brotli)
  * Cache policies
  * Render-blocking resources
  * Unused JavaScript
  * Unused CSS
  * HTTP/2 adoption
  * Code minification
- Frontend optimization checklist with color-coded warnings
- Export buttons integrated into results UI

Technical Implementation:
- Created lib/optimization-checker.js with Lighthouse audit analysis
- Added optimization score calculation (0-100%)
- Potential time savings displayed for each check
- Export buttons wired to download endpoints
- Optimization data saved alongside each test result
This commit is contained in:
2025-12-28 01:41:33 +11:00
parent 57c5209108
commit fd67a8a4fa
5 changed files with 211 additions and 2 deletions

21
main.js
View File

@@ -122,6 +122,14 @@ function displayResults(data) {
if (typeof renderContentBreakdown === 'function') {
renderContentBreakdown(data.id);
}
// Load and display optimizations
loadOptimizations(data.id);
// Wire export buttons
document.getElementById('export-buttons').style.display = 'block';
document.getElementById('export-har').href = `/api/export/${data.id}/har`;
document.getElementById('export-csv').href = `/api/export/${data.id}/csv`;
resultsArea.classList.add('visible');
@@ -238,9 +246,18 @@ function getUserUuid() {
let uuid = localStorage.getItem('user_uuid');
if (!uuid) {
uuid = crypto.randomUUID();
localStorage.setItem('user_uuid', uuid);
});
if (data.checks.length === 0) {
html = '<p style="text-align: center; color: var(--color-text-secondary);">✅ All optimization checks passed!</p>';
}
itemsEl.innerHTML = html;
container.style.display = 'block';
} catch (error) {
console.error('Failed to load optimizations:', error);
}
return uuid;
}
// Initialization