<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ماذا نزّلت هذه الصفحة؟</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 720px; margin: 24px auto; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid #ddd; padding: 6px; text-align: start; }
.big { background: #fef3c7; }
</style>
</head>
<body>
<h1>ماذا نزّلت هذه الصفحة؟</h1>
<p>تعرض لوحة Network كل طلب ترسله الصفحة. وتستطيع الصفحة أن تطلب القائمة نفسها من المتصفح بـ <code>performance.getEntriesByType("resource")</code>. هذه الصفحة تحمّل صورة وملف تنسيق، ثم تعرض طلباتها.</p>
<img src="../../../ch05/examples/bit.svg" alt="بِت، الروبوت" width="96">
<p id="summary"></p>
<table>
<thead><tr><th>الملف</th><th>النوع</th><th>الحجم (بايت)</th></tr></thead>
<tbody id="list"></tbody>
</table>
<script>
window.addEventListener("load", () => {
// الصفحة نفسها طلب أيضاً.
const page = performance.getEntriesByType("navigation")[0];
const files = [page, ...performance.getEntriesByType("resource")];
const size = (f) => f.transferSize || f.encodedBodySize || 0;
const largest = files.reduce((a, b) => (size(b) > size(a) ? b : a));
document.querySelector("#summary").textContent =
`الطلبات: ${files.length}. أكبر ملف: ${largest.name.split("/").pop() || "/"}`;
for (const f of files) {
const row = document.createElement("tr");
if (f === largest) row.className = "big";
row.innerHTML = `<td>${f.name.split("/").pop() || "/"}</td><td>${f.initiatorType}</td><td>${size(f)}</td>`;
document.querySelector("#list").append(row);
}
});
</script>
</body>
</html>