နားလည်ထားရမယ့် အချက်
Browser ဆိုတာ URL box တစ်ခုနဲ့ page ပြနေတဲ့ window တစ်ခုသက်သက် မဟုတ်ပါဘူး — job အများကြီး တစ်ပြိုင်နက် လုပ်နေတဲ့ software ရှုပ်ထွေးတစ်ခုပါ။
Request
server ဆီကို HTML file, image, script file တွေ တောင်းပါတယ်။
Parse
HTML ကို parse လုပ်ပြီး DOM tree တစ်ခု တည်ဆောက်ပါတယ်။
Style
CSS ကို apply လုပ်ပြီး layout/style ဆုံးဖြတ်ပါတယ်။
Execute
JavaScript ကို execute လုပ်ပြီး interactivity/logic ကို အလုပ်လုပ်စေပါတယ်။
Render
အားလုံးကို ပေါင်းစပ်ပြီး screen ပေါ်မှာ pixel အဖြစ် render လုပ်ပေးပါတယ်။
Browser ဟာ local state အချို့ကိုလည်း သိမ်းဆည်းပေးပါတယ် — cookies နဲ့ localStorage ရှိတယ်ဆိုတာကို ဒီနေရာမှာ ဖော်ပြရုံသာ ပြုပါမယ်၊ cookies ကို နောက်ပိုင်း lesson မှာ နက်နက်နဲနဲ ဆက်ရှင်းပါမယ်။
Security rule တွေကိုလည်း enforce လုပ်တယ်
site တစ်ခုက data ကို site တစ်ခြားဆီ လွတ်လွတ်လပ်လပ် ဝင်မယူနိုင်အောင် ကန့်သတ်ချက်တွေ ရှိပါတယ်။
ဒီ job အားလုံးကို လုပ်ဆောင်ပေးတဲ့ core component ကို browser engine လို့ခေါ်ပါတယ် — Chrome/Edge က Blink, Firefox က Gecko, Safari က WebKit ကို သုံးပါတယ်။ engine internals ကတော့ ဒီ course scope အပြင်ဘက်ပါ။
- Browser Engine
- HTML parse, CSS apply, JavaScript execute, page render လုပ်ဆောင်တဲ့ browser ရဲ့ core software component ပါ — Chrome/Edge က Blink, Firefox က Gecko, Safari က WebKit ကို သုံးပါတယ်။
HTML + CSS + JS -> BROWSER -> RENDERED PAGE
-------------------------------------------
HTML ---\
CSS ----> BROWSER ---> RENDERED PAGE
JS ---/
Inside the browser:
1. Request resources
2. Parse HTML (build DOM)
3. Apply CSS (build styles)
4. Execute JS (run logic)
5. Render pixels to screen
(also: stores cookies/localStorage,
enforces browser security rules)လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
code ဥပမာမှာ page ingredient (html, cssRuleCount, jsScriptCount) ကို input အဖြစ်ယူပြီး browser က လုပ်ဆောင်မယ့် processing step order list ကို return ပေးတဲ့ function ကို run ကြည့်ပါမယ်။
- Text-only page — Parse HTML, Layout, Paint (step 3 ခု)
- Styled page — CSSOM apply + render tree ပေါင်းတာ ထပ်ပါ (step 5 ခု)
- Interactive page — Execute script step ပါလာ (step 6 ခု)
ဒီ function ဟာ real browser engine pipeline ကို တိကျစွာ simulate လုပ်တာ မဟုတ်ပါဘူး — ingredient ပါ/မပါအလိုက် step order ဘယ်လို ကြီးလာလဲ ဆိုတဲ့ conceptual illustration ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
function getProcessingSteps(page) {
const { html, cssRuleCount, jsScriptCount } = page;
const steps = [];
if (html) steps.push("Parse HTML into the DOM tree");
if (cssRuleCount > 0) steps.push(`Apply ${cssRuleCount} CSS rule(s) to build styles (CSSOM)`);
if (html && cssRuleCount > 0) steps.push("Combine DOM + CSSOM into a render tree");
if (jsScriptCount > 0) steps.push(`Execute ${jsScriptCount} script(s)`);
steps.push("Layout: calculate size/position of each element");
steps.push("Paint: draw pixels to the screen");
return steps;
}
const textOnlyPage = { html: "<p>Hello</p>", cssRuleCount: 0, jsScriptCount: 0 };
const styledPage = { html: "<p>Hello</p>", cssRuleCount: 3, jsScriptCount: 0 };
const interactivePage = { html: "<button>Click</button>", cssRuleCount: 2, jsScriptCount: 1 };
for (const [name, page] of [
["Text-only page", textOnlyPage],
["Styled page", styledPage],
["Interactive page", interactivePage],
]) {
console.log(`${name}:`);
getProcessingSteps(page).forEach((step, i) => console.log(` ${i + 1}. ${step}`));
}Text-only page:
1. Parse HTML into the DOM tree
2. Layout: calculate size/position of each element
3. Paint: draw pixels to the screen
Styled page:
1. Parse HTML into the DOM tree
2. Apply 3 CSS rule(s) to build styles (CSSOM)
3. Combine DOM + CSSOM into a render tree
4. Layout: calculate size/position of each element
5. Paint: draw pixels to the screen
Interactive page:
1. Parse HTML into the DOM tree
2. Apply 2 CSS rule(s) to build styles (CSSOM)
3. Combine DOM + CSSOM into a render tree
4. Execute 1 script(s)
5. Layout: calculate size/position of each element
6. Paint: draw pixels to the screen၅ မိနစ် စမ်းကြည့်
cssRuleCount: 0, jsScriptCount: 2 ရှိတဲ့ page object တစ်ခု ဖန်တီးပါ (JS ရှိပေမယ့် CSS မရှိတဲ့ page)။ step ဘယ်နှစ်ခု ထွက်လာမလဲ ခန့်မှန်းပြီး run ကြည့်ပါ။
သတိလေးတစ်ချက်
Browser ကို HTML ကိုပြသနေတဲ့ window လို့ပဲ ရိုးရှင်းစွာ ထင်တတ်ကြတယ် — parse/execute/render pipeline တစ်ခုလုံး လုပ်နေတာကို ချန်ထားတတ်ကြတယ်
Browser engine အားလုံး အတိအကျ တူညီပုံစံ render လုပ်တယ်လို့ ထင်တတ်ကြတယ် — engine ကွဲပြားတာကြောင့် ရလဒ် အနည်းငယ် ကွဲနိုင်ပါတယ်
MDN Web Docs — How browsers work — How the Web Works