နားလည်ထားရမယ့် အချက်
ဒီ project မှာ theory အသစ်မရှိပါဘူး — URL-lifecycle lesson နဲ့ client/server mental model ကို https://shop.example.com/products?category=shoes ဆိုတဲ့ တကယ့် URL၊ domain အလွတ်မဟုတ်ဘဲ query string ပါတဲ့ URL တစ်ခုပေါ်မှာ အတူတကွ run ကြည့်ခိုင်းတာပါ။
- Browser (client): URL ကို scheme, host, path, query အဖြစ် parse လုပ်ပြီး ကိုယ်ပိုင် cache ကို စစ်ပြီး IP address လိုအပ်ကြောင်း ဆုံးဖြတ်ပါတယ်။
- DNS resolver: shop.example.com ကို IP address အဖြစ် ပြောင်းပေးရုံ တာဝန်တစ်ခုတည်းရှိတဲ့ server တစ်ခုပါပဲ။
- Server ဒါမှမဟုတ် CDN: TLS handshake ပြီးနောက် အလုပ်အားလုံး — request ဖတ်ခြင်း၊ /products?category=shoes ရဲ့ အဓိပ္ပာယ်ဆုံးဖြတ်ခြင်း၊ response တည်ဆောက်ခြင်း။
Query string က special protocol မဟုတ်ပါ
?category=shoes ဆိုတာ protocol အသစ်တစ်ခုမဟုတ်ဘဲ browser က request line ပေါ်မှာ ပူးတွဲထည့်ပေးလိုက်တဲ့ extra information တစ်ခုမျှသာ server ဖတ်ဖို့ ဖြစ်ပါတယ်။
Wire ပေါ်ထွက်သွားတဲ့ host header အတိအကျနဲ့ server မြင်ရမယ့် query parameter အတိအကျကို ရှင်းပြနိုင်ဖို့ကပဲ lifecycle ကို တကယ်နားလည်စေတာပါ။ TLS/CDN configuration အသေးစိတ်ကို Cloud & Deployment tutorial မှာ ကြည့်နိုင်ပါတယ်။
REQUEST LIFECYCLE FOR ONE URL
-----------------------------
TRACE: https://shop.example.com/products?category=shoes
-----------------------------------------------------------
[Browser]
1. Parse URL -> host=shop.example.com path=/products
2. Check browser cache + DNS cache
|
v
[DNS Resolver]
3. Resolve shop.example.com -> IP address
|
v
[Network]
4. Open TCP connection to IP on port 443
|
v
[TLS]
5. TLS handshake (scheme is https)
|
v
[Browser]
6. Send GET /products?category=shoes
Host: shop.example.com
|
v
[Server / CDN for shop.example.com]
7. Request routed to CDN edge or origin server
8. Server responds: status + headers + HTML body
|
v
[Browser]
9. Parse HTML -> build DOM
10. Fetch CSS, JS, images referenced in the HTML
11. Render: DOM + CSSOM + JS -> pixels showing shoesလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
URL-lifecycle steps တွေနဲ့ client/server roles တွေ — ရှိပြီးသား lesson နှစ်ခုကိုပဲ သုံးပြီး trace ကို လုပ်ကြည့်ပါ။
URL အပိုင်းတွေကို လက်ရေးရေးပါ
Code မတို့ခင် shop.example.com/products?category=shoes ကို scheme, host, path, query အဖြစ် ခွဲရေးပါ။
Parse + cache စစ်ခြင်း
Browser က URL ကို parse လုပ်ပြီး shop.example.com အတွက် ကိုယ်ပိုင် cache နဲ့ DNS cache ကို စစ်ပါတယ်။
DNS က host ကို resolve လုပ်ပါတယ်
DNS resolver က shop.example.com ကို IP address အဖြစ် ပြောင်းပေးပါတယ်။
TCP connection ဖွင့်ပါ
Browser က ရရှိထားတဲ့ IP address ကို port 443 ပေါ်မှာ TCP connection ဖွင့်ပါတယ်။
TLS handshake
Scheme က https ဖြစ်လို့ ဘာမှမပို့ခင် browser နဲ့ server က TLS ကို negotiate လုပ်ပါတယ်။
HTTP request ပို့ပါ
Browser က Host: shop.example.com header နဲ့ GET /products?category=shoes ကို ပို့လိုက်ပါတယ်။
Server ဒါမှမဟုတ် CDN က ကိုင်တွယ်ပါတယ်
Request က shop.example.com ရှေ့ကရှိတဲ့ CDN edge ဒါမှမဟုတ် origin server ဆီ ရောက်ပါတယ်။
Server က response ပြန်ပါတယ်
Server က /products အတွက် status code, header, HTML body ပါတဲ့ response ပြန်ပေးပါတယ်။
Browser က HTML ကို parse လုပ်ပါတယ်
Browser က response body ကနေ DOM ကို တည်ဆောက်ပါတယ်။
Subresource တွေ ဆွဲယူပါ
Browser က HTML ထဲကိုးကားထားတဲ့ CSS, JS, images တွေကို ရှာပြီး ဆွဲယူပါတယ်။
Render လုပ်ခြင်း
DOM + CSSOM + JS ပေါင်းပြီး shoes တွေပြထားတဲ့ page ကို render လုပ်ပါတယ်။
traceRequest ကို ဥပမာ URL နဲ့ run ကြည့်ပြီး output ကို ဒီ list နဲ့ line တစ်ကြောင်းချင်းစီ နှိုင်းယှဉ်ကြည့်ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
function traceRequest(rawUrl) {
const u = new URL(rawUrl);
const port = u.port || (u.protocol === 'https:' ? '443' : '80');
return [
`1. Parse URL - scheme=${u.protocol.replace(':', '')}, host=${u.hostname}, path=${u.pathname}, query=${u.search}`,
`2. Check caches - browser checks its cache and DNS cache for ${u.hostname}`,
`3. DNS resolution - resolve ${u.hostname} to an IP address`,
`4. TCP connect - open a TCP connection to the IP on port ${port}`,
`5. TLS handshake - ${u.protocol === 'https:' ? 'negotiate TLS because scheme is https' : 'skipped, scheme is http'}`,
`6. Send request - GET ${u.pathname}${u.search} with Host: ${u.hostname}`,
`7. Server/CDN - request reaches server or CDN in front of ${u.hostname}`,
`8. Server responds - status code, headers, and HTML body for ${u.pathname}`,
`9. Parse HTML - browser builds the DOM from the response body`,
`10. Fetch assets - browser fetches CSS, JS, images referenced in the HTML`,
`11. Render page - DOM + CSSOM + JS produce pixels for category=${u.searchParams.get('category')}`,
];
}
const result = traceRequest('https://shop.example.com/products?category=shoes');
result.forEach((line) => console.log(line));traceRequest('https://shop.example.com/products?category=shoes') ကို run လိုက်ရင် အောက်ပါ step 11 ခုကို အစဉ်လိုက် ထုတ်ပြပါတယ်:
1. Parse URL - scheme=https, host=shop.example.com, path=/products, query=?category=shoes
2. Check caches - browser checks its cache and DNS cache for shop.example.com
3. DNS resolution - resolve shop.example.com to an IP address
4. TCP connect - open a TCP connection to the IP on port 443
5. TLS handshake - negotiate TLS because scheme is https
6. Send request - GET /products?category=shoes with Host: shop.example.com
7. Server/CDN - request reaches server or CDN in front of shop.example.com
8. Server responds - status code, headers, and HTML body for /products
9. Parse HTML - browser builds the DOM from the response body
10. Fetch assets - browser fetches CSS, JS, images referenced in the HTML
11. Render page - DOM + CSSOM + JS produce pixels for category=shoes၅ မိနစ် စမ်းကြည့်
တခြား real-looking URL တစ်ခု ရွေးပါ (ဥပမာ https://api.example.com/v2/users/42?include=orders) ပြီး traceRequest ကို run မခင် step 11 ခုလုံးကို ကိုယ်တိုင် လက်ရေးနဲ့ trace လုပ်ကြည့်ပြီးမှ code နဲ့ စစ်ကြည့်ပါ။
သတိလေးတစ်ချက်
DNS resolution နဲ့ TLS handshake ကို step တစ်ခုတည်းလို့ မှတ်ထင်ခြင်း — တကယ်တော့ network round trip ကွဲနှစ်ခုပါ
Query string က protocol ကို ပြောင်းလဲစေတယ်လို့ ထင်ခြင်း — တကယ်တော့ server က path ကို ဘယ်လိုကိုင်တွယ်မလဲဆိုတာကိုသာ ပြောင်းစေတာပါ
MDN — URL API — How the Web Works