[{"data":1,"prerenderedAt":860},["ShallowReactive",2],{"post-cloudflare-pages-vs-worker":3,"content-query-69Ms6JZ1By":492},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"categoryKey":11,"readTime":12,"body":13,"_type":486,"_id":487,"_source":488,"_file":489,"_stem":490,"_extension":491},"\u002Fposts\u002Fcloudflare-pages-vs-worker","posts",false,"","Cloudflare Pages vs Worker: Nuxt SSR vs Vite SPA + Functions","Tổng hợp Q&A kiến thức cơ bản và dễ nhầm lẫn về Cloudflare Pages, Worker, Nuxt SSR và Vite SPA + Functions.","2026-07-29","architecture","5 min",{"type":14,"children":15,"toc":481},"root",[16,25,29,48,51,78,81,144,147,180,183,193,322,325,357,360,369,419,431,434,451,469],{"type":17,"tag":18,"props":19,"children":21},"element","h3",{"id":20},"tổng-hợp-qa-kiến-thức-cơ-bản-dễ-nhầm-lẫn",[22],{"type":23,"value":24},"text","Tổng hợp Q&A (kiến thức cơ bản & dễ nhầm lẫn)",{"type":17,"tag":26,"props":27,"children":28},"hr",{},[],{"type":17,"tag":30,"props":31,"children":32},"p",{},[33,39,41,46],{"type":17,"tag":34,"props":35,"children":36},"strong",{},[37],{"type":23,"value":38},"Q: Nitro là gì?",{"type":23,"value":40},"\nA: Nitro là server engine của Nuxt — một build tool\u002Fcompiler đa target. Nó ",{"type":17,"tag":34,"props":42,"children":43},{},[44],{"type":23,"value":45},"không",{"type":23,"value":47}," gắn cứng với \"local\" hay \"static\". Tùy preset cấu hình, Nitro sẽ đóng gói server logic thành output khác nhau: Node.js server, AWS Lambda, Vercel Function, Deno, hoặc Cloudflare Worker.",{"type":17,"tag":26,"props":49,"children":50},{},[],{"type":17,"tag":30,"props":52,"children":53},{},[54,76],{"type":17,"tag":34,"props":55,"children":56},{},[57,59,66,68,74],{"type":23,"value":58},"Q: Nuxt build static (",{"type":17,"tag":60,"props":61,"children":63},"code",{"className":62},[],[64],{"type":23,"value":65},"nuxi generate",{"type":23,"value":67},", preset ",{"type":17,"tag":60,"props":69,"children":71},{"className":70},[],[72],{"type":23,"value":73},"static",{"type":23,"value":75},") thì Nitro làm gì?",{"type":23,"value":77},"\nA: Nitro chạy ở local\u002FCI, pre-render toàn bộ route ra HTML\u002FJS tĩnh, rồi \"biến mất\". Không có server nào tồn tại lúc runtime. Cloudflare Pages lúc này chỉ đóng vai trò CDN phục vụ file tĩnh — bản chất giống hệt một SPA.",{"type":17,"tag":26,"props":79,"children":80},{},[],{"type":17,"tag":30,"props":82,"children":83},{},[84,105,107,112,114,120,122,135,137,142],{"type":17,"tag":34,"props":85,"children":86},{},[87,89,95,97,103],{"type":23,"value":88},"Q: Nuxt build với SSR preset (",{"type":17,"tag":60,"props":90,"children":92},{"className":91},[],[93],{"type":23,"value":94},"cloudflare_pages",{"type":23,"value":96}," \u002F ",{"type":17,"tag":60,"props":98,"children":100},{"className":99},[],[101],{"type":23,"value":102},"cloudflare_module",{"type":23,"value":104},") thì khác gì?",{"type":23,"value":106},"\nA: Nitro ",{"type":17,"tag":34,"props":108,"children":109},{},[110],{"type":23,"value":111},"compile chính nó",{"type":23,"value":113}," (SSR renderer + toàn bộ route trong ",{"type":17,"tag":60,"props":115,"children":117},{"className":116},[],[118],{"type":23,"value":119},"server\u002Fapi\u002F",{"type":23,"value":121},") thành ",{"type":17,"tag":34,"props":123,"children":124},{},[125,127,133],{"type":23,"value":126},"một file JS (",{"type":17,"tag":60,"props":128,"children":130},{"className":129},[],[131],{"type":23,"value":132},"_worker.js",{"type":23,"value":134},") chạy trên Workers runtime",{"type":23,"value":136},". File này không chạy ở local — nó được deploy và ",{"type":17,"tag":34,"props":138,"children":139},{},[140],{"type":23,"value":141},"thực thi trên mỗi request",{"type":23,"value":143}," tại edge của Cloudflare.",{"type":17,"tag":26,"props":145,"children":146},{},[],{"type":17,"tag":30,"props":148,"children":149},{},[150,155,157,163,165,171,173,178],{"type":17,"tag":34,"props":151,"children":152},{},[153],{"type":23,"value":154},"Q: Vậy trong trường hợp SSR, Nitro có phải chính là Worker không?",{"type":23,"value":156},"\nA: Đúng. Nitro server = Worker script thật sự = entry point (",{"type":17,"tag":60,"props":158,"children":160},{"className":159},[],[161],{"type":23,"value":162},"fetch",{"type":23,"value":164}," handler) mà Cloudflare gọi mỗi khi có request. Mọi request (page SSR lẫn ",{"type":17,"tag":60,"props":166,"children":168},{"className":167},[],[169],{"type":23,"value":170},"\u002Fapi\u002F...",{"type":23,"value":172},") đều đi vào ",{"type":17,"tag":34,"props":174,"children":175},{},[176],{"type":23,"value":177},"cùng một Worker đó",{"type":23,"value":179},", Nitro tự route nội bộ. Static assets (ảnh, css, JS bundle client) vẫn được CDN serve trực tiếp, không qua Worker.",{"type":17,"tag":26,"props":181,"children":182},{},[],{"type":17,"tag":30,"props":184,"children":185},{},[186,191],{"type":17,"tag":34,"props":187,"children":188},{},[189],{"type":23,"value":190},"Q: So với Vite SPA + Cloudflare Pages Functions thì sao?",{"type":23,"value":192},"\nA:",{"type":17,"tag":194,"props":195,"children":196},"table",{},[197,219],{"type":17,"tag":198,"props":199,"children":200},"thead",{},[201],{"type":17,"tag":202,"props":203,"children":204},"tr",{},[205,209,214],{"type":17,"tag":206,"props":207,"children":208},"th",{},[],{"type":17,"tag":206,"props":210,"children":211},{},[212],{"type":23,"value":213},"Nuxt SSR",{"type":17,"tag":206,"props":215,"children":216},{},[217],{"type":23,"value":218},"Vite SPA + Functions",{"type":17,"tag":220,"props":221,"children":222},"tbody",{},[223,242,272,298],{"type":17,"tag":202,"props":224,"children":225},{},[226,232,237],{"type":17,"tag":227,"props":228,"children":229},"td",{},[230],{"type":23,"value":231},"Rendering",{"type":17,"tag":227,"props":233,"children":234},{},[235],{"type":23,"value":236},"SSR động mỗi request qua Nitro",{"type":17,"tag":227,"props":238,"children":239},{},[240],{"type":23,"value":241},"Chỉ static HTML\u002FJS, không SSR",{"type":17,"tag":202,"props":243,"children":244},{},[245,250,261],{"type":17,"tag":227,"props":246,"children":247},{},[248],{"type":23,"value":249},"API",{"type":17,"tag":227,"props":251,"children":252},{},[253,259],{"type":17,"tag":60,"props":254,"children":256},{"className":255},[],[257],{"type":23,"value":258},"server\u002Fapi\u002F*.ts",{"type":23,"value":260},", Nitro gộp chung vào 1 Worker với SSR",{"type":17,"tag":227,"props":262,"children":263},{},[264,270],{"type":17,"tag":60,"props":265,"children":267},{"className":266},[],[268],{"type":23,"value":269},"functions\u002F*.ts",{"type":23,"value":271},", file-based routing tách biệt khỏi frontend",{"type":17,"tag":202,"props":273,"children":274},{},[275,280,285],{"type":17,"tag":227,"props":276,"children":277},{},[278],{"type":23,"value":279},"Entry point",{"type":17,"tag":227,"props":281,"children":282},{},[283],{"type":23,"value":284},"1 Worker duy nhất xử lý mọi thứ (page + API)",{"type":17,"tag":227,"props":286,"children":287},{},[288,290,296],{"type":23,"value":289},"CDN serve static asset trực tiếp; chỉ ",{"type":17,"tag":60,"props":291,"children":293},{"className":292},[],[294],{"type":23,"value":295},"\u002Ffunctions\u002F*",{"type":23,"value":297}," mới là Worker riêng theo path",{"type":17,"tag":202,"props":299,"children":300},{},[301,306,311],{"type":17,"tag":227,"props":302,"children":303},{},[304],{"type":23,"value":305},"Build output",{"type":17,"tag":227,"props":307,"children":308},{},[309],{"type":23,"value":310},"1 (hoặc vài) worker bundle tự sinh",{"type":17,"tag":227,"props":312,"children":313},{},[314,320],{"type":17,"tag":60,"props":315,"children":317},{"className":316},[],[318],{"type":23,"value":319},"dist\u002F",{"type":23,"value":321}," (static) + Functions riêng, Cloudflare tự ghép routing",{"type":17,"tag":26,"props":323,"children":324},{},[],{"type":17,"tag":30,"props":326,"children":327},{},[328,333,335,340,342,348,350,355],{"type":17,"tag":34,"props":329,"children":330},{},[331],{"type":23,"value":332},"Q: Vậy về bản chất backend, cả hai target ra có giống nhau không?",{"type":23,"value":334},"\nA: Có — cả hai đều chạy trên ",{"type":17,"tag":34,"props":336,"children":337},{},[338],{"type":23,"value":339},"cùng một nền tảng: Cloudflare Workers runtime (workerd, V8 isolates)",{"type":23,"value":341},". Cùng bindings (KV, D1, R2, Durable Objects), cùng giới hạn CPU time\u002Fmemory, cùng cơ chế ",{"type":17,"tag":60,"props":343,"children":345},{"className":344},[],[346],{"type":23,"value":347},"wrangler.toml",{"type":23,"value":349},". Khác biệt chỉ nằm ở ",{"type":17,"tag":34,"props":351,"children":352},{},[353],{"type":23,"value":354},"kiến trúc\u002Ftổ chức code",{"type":23,"value":356},": Nitro tự động hoá và gộp SSR + API vào 1 Worker; SPA thì bạn tự viết tay từng Function riêng.",{"type":17,"tag":26,"props":358,"children":359},{},[],{"type":17,"tag":30,"props":361,"children":362},{},[363,368],{"type":17,"tag":34,"props":364,"children":365},{},[366],{"type":23,"value":367},"Q: Khái niệm Worker, Pages, Pages Functions khác nhau thế nào?",{"type":23,"value":192},{"type":17,"tag":370,"props":371,"children":372},"ul",{},[373,391,401],{"type":17,"tag":374,"props":375,"children":376},"li",{},[377,382,384,389],{"type":17,"tag":34,"props":378,"children":379},{},[380],{"type":23,"value":381},"Worker",{"type":23,"value":383}," = đơn vị runtime cơ bản của Cloudflare (V8 isolate chạy ",{"type":17,"tag":60,"props":385,"children":387},{"className":386},[],[388],{"type":23,"value":162},{"type":23,"value":390}," handler) — nền tảng gốc.",{"type":17,"tag":374,"props":392,"children":393},{},[394,399],{"type":17,"tag":34,"props":395,"children":396},{},[397],{"type":23,"value":398},"Pages",{"type":23,"value":400}," = sản phẩm cho static site + CI\u002FCD (git integration).",{"type":17,"tag":374,"props":402,"children":403},{},[404,409,411,417],{"type":17,"tag":34,"props":405,"children":406},{},[407],{"type":23,"value":408},"Pages Functions",{"type":23,"value":410}," = lớp \"đường tắt\" viết Worker code (file trong ",{"type":17,"tag":60,"props":412,"children":414},{"className":413},[],[415],{"type":23,"value":416},"functions\u002F",{"type":23,"value":418},") mà không cần tự quản lý Worker project riêng — Cloudflare tự build thành 1 Worker ẩn, gắn vào route của Pages project đó.",{"type":17,"tag":30,"props":420,"children":421},{},[422,424,429],{"type":23,"value":423},"→ Bản chất: ",{"type":17,"tag":34,"props":425,"children":426},{},[427],{"type":23,"value":428},"Pages Functions = một Worker",{"type":23,"value":430},", chỉ khác là được Cloudflare tạo\u002Fquản lý tự động, gắn chết vào 1 Pages project, không tồn tại độc lập.",{"type":17,"tag":26,"props":432,"children":433},{},[],{"type":17,"tag":30,"props":435,"children":436},{},[437,442,444,449],{"type":17,"tag":34,"props":438,"children":439},{},[440],{"type":23,"value":441},"Q: Tại sao Pages Functions\u002FWorker ẩn khỏi dashboard, không hiện như 1 \"Worker project\" riêng?",{"type":23,"value":443},"\nA: Đây là chủ đích thiết kế — nó là ",{"type":17,"tag":34,"props":445,"children":446},{},[447],{"type":23,"value":448},"managed\u002Finternal Worker",{"type":23,"value":450},", sinh tự động mỗi lần deploy, không nhằm để quản lý trực tiếp như Worker service độc lập. Nó:",{"type":17,"tag":370,"props":452,"children":453},{},[454,459,464],{"type":17,"tag":374,"props":455,"children":456},{},[457],{"type":23,"value":458},"Không có tên riêng, không xuất hiện ở tab \"Workers & Pages → Workers\"",{"type":17,"tag":374,"props":460,"children":461},{},[462],{"type":23,"value":463},"Không có route\u002Fdomain binding riêng để chỉnh tay",{"type":17,"tag":374,"props":465,"children":466},{},[467],{"type":23,"value":468},"Chỉ sống\u002Fchết theo vòng đời của Pages project (mỗi deployment tạo bản mới)",{"type":17,"tag":30,"props":470,"children":471},{},[472,474,479],{"type":23,"value":473},"Mục đích: đơn giản hoá trải nghiệm, ẩn khái niệm Worker khỏi người dùng Pages thông thường. Muốn full control (routes, triggers, versioning, observability riêng) → phải tạo ",{"type":17,"tag":34,"props":475,"children":476},{},[477],{"type":23,"value":478},"Worker project",{"type":23,"value":480}," thật sự, tách biệt khỏi Pages.",{"title":7,"searchDepth":482,"depth":482,"links":483},2,[484],{"id":20,"depth":485,"text":24},3,"markdown","content:posts:cloudflare-pages-vs-worker.md","content","posts\u002Fcloudflare-pages-vs-worker.md","posts\u002Fcloudflare-pages-vs-worker","md",{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"categoryKey":11,"readTime":12,"body":493,"_type":486,"_id":487,"_source":488,"_file":489,"_stem":490,"_extension":491},{"type":14,"children":494,"toc":857},[495,499,502,515,518,538,541,588,591,616,619,627,731,734,758,761,769,808,817,820,833,848],{"type":17,"tag":18,"props":496,"children":497},{"id":20},[498],{"type":23,"value":24},{"type":17,"tag":26,"props":500,"children":501},{},[],{"type":17,"tag":30,"props":503,"children":504},{},[505,509,510,514],{"type":17,"tag":34,"props":506,"children":507},{},[508],{"type":23,"value":38},{"type":23,"value":40},{"type":17,"tag":34,"props":511,"children":512},{},[513],{"type":23,"value":45},{"type":23,"value":47},{"type":17,"tag":26,"props":516,"children":517},{},[],{"type":17,"tag":30,"props":519,"children":520},{},[521,537],{"type":17,"tag":34,"props":522,"children":523},{},[524,525,530,531,536],{"type":23,"value":58},{"type":17,"tag":60,"props":526,"children":528},{"className":527},[],[529],{"type":23,"value":65},{"type":23,"value":67},{"type":17,"tag":60,"props":532,"children":534},{"className":533},[],[535],{"type":23,"value":73},{"type":23,"value":75},{"type":23,"value":77},{"type":17,"tag":26,"props":539,"children":540},{},[],{"type":17,"tag":30,"props":542,"children":543},{},[544,560,561,565,566,571,572,582,583,587],{"type":17,"tag":34,"props":545,"children":546},{},[547,548,553,554,559],{"type":23,"value":88},{"type":17,"tag":60,"props":549,"children":551},{"className":550},[],[552],{"type":23,"value":94},{"type":23,"value":96},{"type":17,"tag":60,"props":555,"children":557},{"className":556},[],[558],{"type":23,"value":102},{"type":23,"value":104},{"type":23,"value":106},{"type":17,"tag":34,"props":562,"children":563},{},[564],{"type":23,"value":111},{"type":23,"value":113},{"type":17,"tag":60,"props":567,"children":569},{"className":568},[],[570],{"type":23,"value":119},{"type":23,"value":121},{"type":17,"tag":34,"props":573,"children":574},{},[575,576,581],{"type":23,"value":126},{"type":17,"tag":60,"props":577,"children":579},{"className":578},[],[580],{"type":23,"value":132},{"type":23,"value":134},{"type":23,"value":136},{"type":17,"tag":34,"props":584,"children":585},{},[586],{"type":23,"value":141},{"type":23,"value":143},{"type":17,"tag":26,"props":589,"children":590},{},[],{"type":17,"tag":30,"props":592,"children":593},{},[594,598,599,604,605,610,611,615],{"type":17,"tag":34,"props":595,"children":596},{},[597],{"type":23,"value":154},{"type":23,"value":156},{"type":17,"tag":60,"props":600,"children":602},{"className":601},[],[603],{"type":23,"value":162},{"type":23,"value":164},{"type":17,"tag":60,"props":606,"children":608},{"className":607},[],[609],{"type":23,"value":170},{"type":23,"value":172},{"type":17,"tag":34,"props":612,"children":613},{},[614],{"type":23,"value":177},{"type":23,"value":179},{"type":17,"tag":26,"props":617,"children":618},{},[],{"type":17,"tag":30,"props":620,"children":621},{},[622,626],{"type":17,"tag":34,"props":623,"children":624},{},[625],{"type":23,"value":190},{"type":23,"value":192},{"type":17,"tag":194,"props":628,"children":629},{},[630,647],{"type":17,"tag":198,"props":631,"children":632},{},[633],{"type":17,"tag":202,"props":634,"children":635},{},[636,639,643],{"type":17,"tag":206,"props":637,"children":638},{},[],{"type":17,"tag":206,"props":640,"children":641},{},[642],{"type":23,"value":213},{"type":17,"tag":206,"props":644,"children":645},{},[646],{"type":23,"value":218},{"type":17,"tag":220,"props":648,"children":649},{},[650,665,690,711],{"type":17,"tag":202,"props":651,"children":652},{},[653,657,661],{"type":17,"tag":227,"props":654,"children":655},{},[656],{"type":23,"value":231},{"type":17,"tag":227,"props":658,"children":659},{},[660],{"type":23,"value":236},{"type":17,"tag":227,"props":662,"children":663},{},[664],{"type":23,"value":241},{"type":17,"tag":202,"props":666,"children":667},{},[668,672,681],{"type":17,"tag":227,"props":669,"children":670},{},[671],{"type":23,"value":249},{"type":17,"tag":227,"props":673,"children":674},{},[675,680],{"type":17,"tag":60,"props":676,"children":678},{"className":677},[],[679],{"type":23,"value":258},{"type":23,"value":260},{"type":17,"tag":227,"props":682,"children":683},{},[684,689],{"type":17,"tag":60,"props":685,"children":687},{"className":686},[],[688],{"type":23,"value":269},{"type":23,"value":271},{"type":17,"tag":202,"props":691,"children":692},{},[693,697,701],{"type":17,"tag":227,"props":694,"children":695},{},[696],{"type":23,"value":279},{"type":17,"tag":227,"props":698,"children":699},{},[700],{"type":23,"value":284},{"type":17,"tag":227,"props":702,"children":703},{},[704,705,710],{"type":23,"value":289},{"type":17,"tag":60,"props":706,"children":708},{"className":707},[],[709],{"type":23,"value":295},{"type":23,"value":297},{"type":17,"tag":202,"props":712,"children":713},{},[714,718,722],{"type":17,"tag":227,"props":715,"children":716},{},[717],{"type":23,"value":305},{"type":17,"tag":227,"props":719,"children":720},{},[721],{"type":23,"value":310},{"type":17,"tag":227,"props":723,"children":724},{},[725,730],{"type":17,"tag":60,"props":726,"children":728},{"className":727},[],[729],{"type":23,"value":319},{"type":23,"value":321},{"type":17,"tag":26,"props":732,"children":733},{},[],{"type":17,"tag":30,"props":735,"children":736},{},[737,741,742,746,747,752,753,757],{"type":17,"tag":34,"props":738,"children":739},{},[740],{"type":23,"value":332},{"type":23,"value":334},{"type":17,"tag":34,"props":743,"children":744},{},[745],{"type":23,"value":339},{"type":23,"value":341},{"type":17,"tag":60,"props":748,"children":750},{"className":749},[],[751],{"type":23,"value":347},{"type":23,"value":349},{"type":17,"tag":34,"props":754,"children":755},{},[756],{"type":23,"value":354},{"type":23,"value":356},{"type":17,"tag":26,"props":759,"children":760},{},[],{"type":17,"tag":30,"props":762,"children":763},{},[764,768],{"type":17,"tag":34,"props":765,"children":766},{},[767],{"type":23,"value":367},{"type":23,"value":192},{"type":17,"tag":370,"props":770,"children":771},{},[772,786,794],{"type":17,"tag":374,"props":773,"children":774},{},[775,779,780,785],{"type":17,"tag":34,"props":776,"children":777},{},[778],{"type":23,"value":381},{"type":23,"value":383},{"type":17,"tag":60,"props":781,"children":783},{"className":782},[],[784],{"type":23,"value":162},{"type":23,"value":390},{"type":17,"tag":374,"props":787,"children":788},{},[789,793],{"type":17,"tag":34,"props":790,"children":791},{},[792],{"type":23,"value":398},{"type":23,"value":400},{"type":17,"tag":374,"props":795,"children":796},{},[797,801,802,807],{"type":17,"tag":34,"props":798,"children":799},{},[800],{"type":23,"value":408},{"type":23,"value":410},{"type":17,"tag":60,"props":803,"children":805},{"className":804},[],[806],{"type":23,"value":416},{"type":23,"value":418},{"type":17,"tag":30,"props":809,"children":810},{},[811,812,816],{"type":23,"value":423},{"type":17,"tag":34,"props":813,"children":814},{},[815],{"type":23,"value":428},{"type":23,"value":430},{"type":17,"tag":26,"props":818,"children":819},{},[],{"type":17,"tag":30,"props":821,"children":822},{},[823,827,828,832],{"type":17,"tag":34,"props":824,"children":825},{},[826],{"type":23,"value":441},{"type":23,"value":443},{"type":17,"tag":34,"props":829,"children":830},{},[831],{"type":23,"value":448},{"type":23,"value":450},{"type":17,"tag":370,"props":834,"children":835},{},[836,840,844],{"type":17,"tag":374,"props":837,"children":838},{},[839],{"type":23,"value":458},{"type":17,"tag":374,"props":841,"children":842},{},[843],{"type":23,"value":463},{"type":17,"tag":374,"props":845,"children":846},{},[847],{"type":23,"value":468},{"type":17,"tag":30,"props":849,"children":850},{},[851,852,856],{"type":23,"value":473},{"type":17,"tag":34,"props":853,"children":854},{},[855],{"type":23,"value":478},{"type":23,"value":480},{"title":7,"searchDepth":482,"depth":482,"links":858},[859],{"id":20,"depth":485,"text":24},1788893805830]