[{"data":1,"prerenderedAt":1253},["ShallowReactive",2],{"content-/topics/engineering/cloudflare-pages-edge-computing-guide":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":5,"tags":11,"author":17,"featured":18,"series":19,"seriesOrder":20,"readingTime":21,"image":22,"body":23,"_type":1247,"_id":1248,"_source":1249,"_file":1250,"_stem":1251,"_extension":1252},"/topics/engineering/cloudflare-pages-edge-computing-guide","engineering",false,"","边缘计算实战：用 Cloudflare Pages 把 TTFB 拉下来","把站点放到边缘，不等于性能自动起飞。本文从网络距离、缓存命中、动态逻辑下沉、回源策略与观测体系五个维度，讲清 Cloudflare Pages 和边缘函数真正能解决什么，不能解决什么。","2026-04-25",[12,13,14,15,16],"Cloudflare Pages","Edge Computing","TTFB","CDN","部署架构","小明",true,"web-performance-extreme",3,13,"/images/articles/cloudflare-pages-edge-computing-guide-cover.jpg",{"type":24,"children":25,"toc":1228},"root",[26,34,40,49,54,79,84,89,98,102,109,114,119,127,132,151,156,159,165,172,177,182,188,193,211,216,222,227,245,250,253,259,264,282,287,295,298,304,309,396,401,404,410,1019,1029,1032,1038,1044,1049,1055,1060,1066,1071,1074,1080,1085,1090,1113,1118,1121,1127,1132,1137,1155,1160,1178,1181,1186,1209,1214,1222],{"type":27,"tag":28,"props":29,"children":31},"element","h1",{"id":30},"边缘计算实战用-cloudflare-pages-把-ttfb-拉下来",[32],{"type":33,"value":8},"text",{"type":27,"tag":35,"props":36,"children":37},"p",{},[38],{"type":33,"value":39},"很多团队第一次听到“边缘计算”，眼睛会瞬间发亮：",{"type":27,"tag":41,"props":42,"children":43},"blockquote",{},[44],{"type":27,"tag":35,"props":45,"children":46},{},[47],{"type":33,"value":48},"代码离用户更近了，那岂不是所有页面都会快？",{"type":27,"tag":35,"props":50,"children":51},{},[52],{"type":33,"value":53},"理想很丰满，现实通常是：",{"type":27,"tag":55,"props":56,"children":57},"ul",{},[58,64,69,74],{"type":27,"tag":59,"props":60,"children":61},"li",{},[62],{"type":33,"value":63},"静态资源确实更快了",{"type":27,"tag":59,"props":65,"children":66},{},[67],{"type":33,"value":68},"某些页面的 TTFB 也降了",{"type":27,"tag":59,"props":70,"children":71},{},[72],{"type":33,"value":73},"但复杂动态接口依旧慢",{"type":27,"tag":59,"props":75,"children":76},{},[77],{"type":33,"value":78},"数据库一旦还在单一区域，远距离回源还是要花钱也花时间",{"type":27,"tag":35,"props":80,"children":81},{},[82],{"type":33,"value":83},"所以边缘计算最需要的不是热情，而是边界感。",{"type":27,"tag":35,"props":85,"children":86},{},[87],{"type":33,"value":88},"Cloudflare Pages 很强，但它不是“全球加速魔法”，它只是给了你一个机会：",{"type":27,"tag":35,"props":90,"children":91},{},[92],{"type":27,"tag":93,"props":94,"children":95},"strong",{},[96],{"type":33,"value":97},"把真正值得靠前执行的逻辑，挪到离用户更近的地方。",{"type":27,"tag":99,"props":100,"children":101},"hr",{},[],{"type":27,"tag":103,"props":104,"children":106},"h2",{"id":105},"_1-边缘真正优化的是什么",[107],{"type":33,"value":108},"1. 边缘真正优化的是什么",{"type":27,"tag":35,"props":110,"children":111},{},[112],{"type":33,"value":113},"很多人把边缘优化理解成“让一切都更快”。",{"type":27,"tag":35,"props":115,"children":116},{},[117],{"type":33,"value":118},"更准确的说法是：",{"type":27,"tag":41,"props":120,"children":121},{},[122],{"type":27,"tag":35,"props":123,"children":124},{},[125],{"type":33,"value":126},"它优先优化的是网络往返距离，以及那些可以在边缘就被拦截、命中、生成的响应。",{"type":27,"tag":35,"props":128,"children":129},{},[130],{"type":33,"value":131},"因此你最容易受益的内容有三类：",{"type":27,"tag":133,"props":134,"children":135},"ol",{},[136,141,146],{"type":27,"tag":59,"props":137,"children":138},{},[139],{"type":33,"value":140},"静态资源",{"type":27,"tag":59,"props":142,"children":143},{},[144],{"type":33,"value":145},"弱动态 HTML",{"type":27,"tag":59,"props":147,"children":148},{},[149],{"type":33,"value":150},"轻量计算和路由裁决逻辑",{"type":27,"tag":35,"props":152,"children":153},{},[154],{"type":33,"value":155},"最不容易直接受益的，是强依赖中心化数据库的复杂动态接口。",{"type":27,"tag":99,"props":157,"children":158},{},[],{"type":27,"tag":103,"props":160,"children":162},{"id":161},"_2-cloudflare-pages-适合下沉什么逻辑",[163],{"type":33,"value":164},"2. Cloudflare Pages 适合下沉什么逻辑",{"type":27,"tag":166,"props":167,"children":169},"h3",{"id":168},"_21-静态资源与页面外壳",[170],{"type":33,"value":171},"2.1 静态资源与页面外壳",{"type":27,"tag":35,"props":173,"children":174},{},[175],{"type":33,"value":176},"这部分最直接，收益也最稳。",{"type":27,"tag":35,"props":178,"children":179},{},[180],{"type":33,"value":181},"比如博客、文档、营销页、产品介绍页，它们的 HTML、CSS、图片本来就适合全球分发。",{"type":27,"tag":166,"props":183,"children":185},{"id":184},"_22-轻度个性化路由",[186],{"type":33,"value":187},"2.2 轻度个性化路由",{"type":27,"tag":35,"props":189,"children":190},{},[191],{"type":33,"value":192},"例如：",{"type":27,"tag":55,"props":194,"children":195},{},[196,201,206],{"type":27,"tag":59,"props":197,"children":198},{},[199],{"type":33,"value":200},"根据国家或语言跳转站点版本",{"type":27,"tag":59,"props":202,"children":203},{},[204],{"type":33,"value":205},"根据实验分组返回不同变体",{"type":27,"tag":59,"props":207,"children":208},{},[209],{"type":33,"value":210},"读取 cookie 做轻量主题切换",{"type":27,"tag":35,"props":212,"children":213},{},[214],{"type":33,"value":215},"这种逻辑在边缘做，能避免请求先跑到中心区域再决定“你该看哪个版本”。",{"type":27,"tag":166,"props":217,"children":219},{"id":218},"_23-缓存友好的聚合接口",[220],{"type":33,"value":221},"2.3 缓存友好的聚合接口",{"type":27,"tag":35,"props":223,"children":224},{},[225],{"type":33,"value":226},"如果某个接口本质是：",{"type":27,"tag":55,"props":228,"children":229},{},[230,235,240],{"type":27,"tag":59,"props":231,"children":232},{},[233],{"type":33,"value":234},"变化不算特别频繁",{"type":27,"tag":59,"props":236,"children":237},{},[238],{"type":33,"value":239},"对每个用户差异不大",{"type":27,"tag":59,"props":241,"children":242},{},[243],{"type":33,"value":244},"但调用量很大",{"type":27,"tag":35,"props":246,"children":247},{},[248],{"type":33,"value":249},"那它就适合边缘缓存甚至边缘计算预处理。",{"type":27,"tag":99,"props":251,"children":252},{},[],{"type":27,"tag":103,"props":254,"children":256},{"id":255},"_3-不适合硬塞到边缘的东西",[257],{"type":33,"value":258},"3. 不适合硬塞到边缘的东西",{"type":27,"tag":35,"props":260,"children":261},{},[262],{"type":33,"value":263},"边缘不是用来炫技的。以下场景强行下沉，常常得不偿失：",{"type":27,"tag":55,"props":265,"children":266},{},[267,272,277],{"type":27,"tag":59,"props":268,"children":269},{},[270],{"type":33,"value":271},"每次都要访问中心数据库的高一致性写操作",{"type":27,"tag":59,"props":273,"children":274},{},[275],{"type":33,"value":276},"需要大量 CPU 的数据处理任务",{"type":27,"tag":59,"props":278,"children":279},{},[280],{"type":33,"value":281},"依赖复杂内网资源和专有连接的业务",{"type":27,"tag":35,"props":283,"children":284},{},[285],{"type":33,"value":286},"一句话：",{"type":27,"tag":41,"props":288,"children":289},{},[290],{"type":27,"tag":35,"props":291,"children":292},{},[293],{"type":33,"value":294},"如果你的主要耗时还在后方系统，边缘最多只能把“路”缩短，不能把“工厂”搬走。",{"type":27,"tag":99,"props":296,"children":297},{},[],{"type":27,"tag":103,"props":299,"children":301},{"id":300},"_4-一个实用架构边缘负责拦截缓存裁决中心负责重业务",[302],{"type":33,"value":303},"4. 一个实用架构：边缘负责拦截、缓存、裁决，中心负责重业务",{"type":27,"tag":35,"props":305,"children":306},{},[307],{"type":33,"value":308},"比较稳妥的做法是把职责分开：",{"type":27,"tag":310,"props":311,"children":312},"table",{},[313,337],{"type":27,"tag":314,"props":315,"children":316},"thead",{},[317],{"type":27,"tag":318,"props":319,"children":320},"tr",{},[321,327,332],{"type":27,"tag":322,"props":323,"children":324},"th",{},[325],{"type":33,"value":326},"层级",{"type":27,"tag":322,"props":328,"children":329},{},[330],{"type":33,"value":331},"负责什么",{"type":27,"tag":322,"props":333,"children":334},{},[335],{"type":33,"value":336},"不负责什么",{"type":27,"tag":338,"props":339,"children":340},"tbody",{},[341,360,378],{"type":27,"tag":318,"props":342,"children":343},{},[344,350,355],{"type":27,"tag":345,"props":346,"children":347},"td",{},[348],{"type":33,"value":349},"边缘",{"type":27,"tag":345,"props":351,"children":352},{},[353],{"type":33,"value":354},"就近分发、缓存命中、轻量重写、实验分流",{"type":27,"tag":345,"props":356,"children":357},{},[358],{"type":33,"value":359},"复杂事务、重型数据聚合",{"type":27,"tag":318,"props":361,"children":362},{},[363,368,373],{"type":27,"tag":345,"props":364,"children":365},{},[366],{"type":33,"value":367},"中心应用",{"type":27,"tag":345,"props":369,"children":370},{},[371],{"type":33,"value":372},"核心业务逻辑、权限、聚合、写操作",{"type":27,"tag":345,"props":374,"children":375},{},[376],{"type":33,"value":377},"全球低延迟分发",{"type":27,"tag":318,"props":379,"children":380},{},[381,386,391],{"type":27,"tag":345,"props":382,"children":383},{},[384],{"type":33,"value":385},"数据层",{"type":27,"tag":345,"props":387,"children":388},{},[389],{"type":33,"value":390},"真正的数据一致性与持久化",{"type":27,"tag":345,"props":392,"children":393},{},[394],{"type":33,"value":395},"页面分发与流量吸收",{"type":27,"tag":35,"props":397,"children":398},{},[399],{"type":33,"value":400},"当你这样拆，系统会更稳定。因为每一层都在做自己擅长的事。",{"type":27,"tag":99,"props":402,"children":403},{},[],{"type":27,"tag":103,"props":405,"children":407},{"id":406},"_5-一个边缘函数例子让弱动态页面先就近命中",[408],{"type":33,"value":409},"5. 一个边缘函数例子：让弱动态页面先就近命中",{"type":27,"tag":411,"props":412,"children":416},"pre",{"className":413,"code":414,"language":415,"meta":7,"style":7},"language-ts shiki shiki-themes github-dark","export async function onRequestGet(context: {\n  request: Request\n  next: () => Promise\u003CResponse>\n  env: Record\u003Cstring, string>\n}) {\n  const cacheKey = new Request(context.request.url, context.request)\n  const cache = caches.default\n\n  const cached = await cache.match(cacheKey)\n  if (cached) {\n    return cached\n  }\n\n  const response = await context.next()\n\n  if (response.ok) {\n    const headers = new Headers(response.headers)\n    headers.set('Cache-Control', 'public, s-maxage=300, stale-while-revalidate=600')\n\n    const cachedResponse = new Response(response.body, {\n      status: response.status,\n      headers,\n    })\n\n    context.waitUntil(cache.put(cacheKey, cachedResponse.clone()))\n    return cachedResponse\n  }\n\n  return response\n}\n","ts",[417],{"type":27,"tag":418,"props":419,"children":420},"code",{"__ignoreMap":7},[421,471,489,531,572,581,615,637,646,683,697,711,720,727,763,771,784,816,854,862,893,902,911,920,928,967,980,988,996,1010],{"type":27,"tag":422,"props":423,"children":426},"span",{"class":424,"line":425},"line",1,[427,433,438,443,449,455,461,466],{"type":27,"tag":422,"props":428,"children":430},{"style":429},"--shiki-default:#F97583",[431],{"type":33,"value":432},"export",{"type":27,"tag":422,"props":434,"children":435},{"style":429},[436],{"type":33,"value":437}," async",{"type":27,"tag":422,"props":439,"children":440},{"style":429},[441],{"type":33,"value":442}," function",{"type":27,"tag":422,"props":444,"children":446},{"style":445},"--shiki-default:#B392F0",[447],{"type":33,"value":448}," onRequestGet",{"type":27,"tag":422,"props":450,"children":452},{"style":451},"--shiki-default:#E1E4E8",[453],{"type":33,"value":454},"(",{"type":27,"tag":422,"props":456,"children":458},{"style":457},"--shiki-default:#FFAB70",[459],{"type":33,"value":460},"context",{"type":27,"tag":422,"props":462,"children":463},{"style":429},[464],{"type":33,"value":465},":",{"type":27,"tag":422,"props":467,"children":468},{"style":451},[469],{"type":33,"value":470}," {\n",{"type":27,"tag":422,"props":472,"children":474},{"class":424,"line":473},2,[475,480,484],{"type":27,"tag":422,"props":476,"children":477},{"style":457},[478],{"type":33,"value":479},"  request",{"type":27,"tag":422,"props":481,"children":482},{"style":429},[483],{"type":33,"value":465},{"type":27,"tag":422,"props":485,"children":486},{"style":445},[487],{"type":33,"value":488}," Request\n",{"type":27,"tag":422,"props":490,"children":491},{"class":424,"line":20},[492,497,501,506,511,516,521,526],{"type":27,"tag":422,"props":493,"children":494},{"style":445},[495],{"type":33,"value":496},"  next",{"type":27,"tag":422,"props":498,"children":499},{"style":429},[500],{"type":33,"value":465},{"type":27,"tag":422,"props":502,"children":503},{"style":451},[504],{"type":33,"value":505}," () ",{"type":27,"tag":422,"props":507,"children":508},{"style":429},[509],{"type":33,"value":510},"=>",{"type":27,"tag":422,"props":512,"children":513},{"style":445},[514],{"type":33,"value":515}," Promise",{"type":27,"tag":422,"props":517,"children":518},{"style":451},[519],{"type":33,"value":520},"\u003C",{"type":27,"tag":422,"props":522,"children":523},{"style":445},[524],{"type":33,"value":525},"Response",{"type":27,"tag":422,"props":527,"children":528},{"style":451},[529],{"type":33,"value":530},">\n",{"type":27,"tag":422,"props":532,"children":534},{"class":424,"line":533},4,[535,540,544,549,553,559,564,568],{"type":27,"tag":422,"props":536,"children":537},{"style":457},[538],{"type":33,"value":539},"  env",{"type":27,"tag":422,"props":541,"children":542},{"style":429},[543],{"type":33,"value":465},{"type":27,"tag":422,"props":545,"children":546},{"style":445},[547],{"type":33,"value":548}," Record",{"type":27,"tag":422,"props":550,"children":551},{"style":451},[552],{"type":33,"value":520},{"type":27,"tag":422,"props":554,"children":556},{"style":555},"--shiki-default:#79B8FF",[557],{"type":33,"value":558},"string",{"type":27,"tag":422,"props":560,"children":561},{"style":451},[562],{"type":33,"value":563},", ",{"type":27,"tag":422,"props":565,"children":566},{"style":555},[567],{"type":33,"value":558},{"type":27,"tag":422,"props":569,"children":570},{"style":451},[571],{"type":33,"value":530},{"type":27,"tag":422,"props":573,"children":575},{"class":424,"line":574},5,[576],{"type":27,"tag":422,"props":577,"children":578},{"style":451},[579],{"type":33,"value":580},"}) {\n",{"type":27,"tag":422,"props":582,"children":584},{"class":424,"line":583},6,[585,590,595,600,605,610],{"type":27,"tag":422,"props":586,"children":587},{"style":429},[588],{"type":33,"value":589},"  const",{"type":27,"tag":422,"props":591,"children":592},{"style":555},[593],{"type":33,"value":594}," cacheKey",{"type":27,"tag":422,"props":596,"children":597},{"style":429},[598],{"type":33,"value":599}," =",{"type":27,"tag":422,"props":601,"children":602},{"style":429},[603],{"type":33,"value":604}," new",{"type":27,"tag":422,"props":606,"children":607},{"style":445},[608],{"type":33,"value":609}," Request",{"type":27,"tag":422,"props":611,"children":612},{"style":451},[613],{"type":33,"value":614},"(context.request.url, context.request)\n",{"type":27,"tag":422,"props":616,"children":618},{"class":424,"line":617},7,[619,623,628,632],{"type":27,"tag":422,"props":620,"children":621},{"style":429},[622],{"type":33,"value":589},{"type":27,"tag":422,"props":624,"children":625},{"style":555},[626],{"type":33,"value":627}," cache",{"type":27,"tag":422,"props":629,"children":630},{"style":429},[631],{"type":33,"value":599},{"type":27,"tag":422,"props":633,"children":634},{"style":451},[635],{"type":33,"value":636}," caches.default\n",{"type":27,"tag":422,"props":638,"children":640},{"class":424,"line":639},8,[641],{"type":27,"tag":422,"props":642,"children":643},{"emptyLinePlaceholder":18},[644],{"type":33,"value":645},"\n",{"type":27,"tag":422,"props":647,"children":649},{"class":424,"line":648},9,[650,654,659,663,668,673,678],{"type":27,"tag":422,"props":651,"children":652},{"style":429},[653],{"type":33,"value":589},{"type":27,"tag":422,"props":655,"children":656},{"style":555},[657],{"type":33,"value":658}," cached",{"type":27,"tag":422,"props":660,"children":661},{"style":429},[662],{"type":33,"value":599},{"type":27,"tag":422,"props":664,"children":665},{"style":429},[666],{"type":33,"value":667}," await",{"type":27,"tag":422,"props":669,"children":670},{"style":451},[671],{"type":33,"value":672}," cache.",{"type":27,"tag":422,"props":674,"children":675},{"style":445},[676],{"type":33,"value":677},"match",{"type":27,"tag":422,"props":679,"children":680},{"style":451},[681],{"type":33,"value":682},"(cacheKey)\n",{"type":27,"tag":422,"props":684,"children":686},{"class":424,"line":685},10,[687,692],{"type":27,"tag":422,"props":688,"children":689},{"style":429},[690],{"type":33,"value":691},"  if",{"type":27,"tag":422,"props":693,"children":694},{"style":451},[695],{"type":33,"value":696}," (cached) {\n",{"type":27,"tag":422,"props":698,"children":700},{"class":424,"line":699},11,[701,706],{"type":27,"tag":422,"props":702,"children":703},{"style":429},[704],{"type":33,"value":705},"    return",{"type":27,"tag":422,"props":707,"children":708},{"style":451},[709],{"type":33,"value":710}," cached\n",{"type":27,"tag":422,"props":712,"children":714},{"class":424,"line":713},12,[715],{"type":27,"tag":422,"props":716,"children":717},{"style":451},[718],{"type":33,"value":719},"  }\n",{"type":27,"tag":422,"props":721,"children":722},{"class":424,"line":21},[723],{"type":27,"tag":422,"props":724,"children":725},{"emptyLinePlaceholder":18},[726],{"type":33,"value":645},{"type":27,"tag":422,"props":728,"children":730},{"class":424,"line":729},14,[731,735,740,744,748,753,758],{"type":27,"tag":422,"props":732,"children":733},{"style":429},[734],{"type":33,"value":589},{"type":27,"tag":422,"props":736,"children":737},{"style":555},[738],{"type":33,"value":739}," response",{"type":27,"tag":422,"props":741,"children":742},{"style":429},[743],{"type":33,"value":599},{"type":27,"tag":422,"props":745,"children":746},{"style":429},[747],{"type":33,"value":667},{"type":27,"tag":422,"props":749,"children":750},{"style":451},[751],{"type":33,"value":752}," context.",{"type":27,"tag":422,"props":754,"children":755},{"style":445},[756],{"type":33,"value":757},"next",{"type":27,"tag":422,"props":759,"children":760},{"style":451},[761],{"type":33,"value":762},"()\n",{"type":27,"tag":422,"props":764,"children":766},{"class":424,"line":765},15,[767],{"type":27,"tag":422,"props":768,"children":769},{"emptyLinePlaceholder":18},[770],{"type":33,"value":645},{"type":27,"tag":422,"props":772,"children":774},{"class":424,"line":773},16,[775,779],{"type":27,"tag":422,"props":776,"children":777},{"style":429},[778],{"type":33,"value":691},{"type":27,"tag":422,"props":780,"children":781},{"style":451},[782],{"type":33,"value":783}," (response.ok) {\n",{"type":27,"tag":422,"props":785,"children":787},{"class":424,"line":786},17,[788,793,798,802,806,811],{"type":27,"tag":422,"props":789,"children":790},{"style":429},[791],{"type":33,"value":792},"    const",{"type":27,"tag":422,"props":794,"children":795},{"style":555},[796],{"type":33,"value":797}," headers",{"type":27,"tag":422,"props":799,"children":800},{"style":429},[801],{"type":33,"value":599},{"type":27,"tag":422,"props":803,"children":804},{"style":429},[805],{"type":33,"value":604},{"type":27,"tag":422,"props":807,"children":808},{"style":445},[809],{"type":33,"value":810}," Headers",{"type":27,"tag":422,"props":812,"children":813},{"style":451},[814],{"type":33,"value":815},"(response.headers)\n",{"type":27,"tag":422,"props":817,"children":819},{"class":424,"line":818},18,[820,825,830,834,840,844,849],{"type":27,"tag":422,"props":821,"children":822},{"style":451},[823],{"type":33,"value":824},"    headers.",{"type":27,"tag":422,"props":826,"children":827},{"style":445},[828],{"type":33,"value":829},"set",{"type":27,"tag":422,"props":831,"children":832},{"style":451},[833],{"type":33,"value":454},{"type":27,"tag":422,"props":835,"children":837},{"style":836},"--shiki-default:#9ECBFF",[838],{"type":33,"value":839},"'Cache-Control'",{"type":27,"tag":422,"props":841,"children":842},{"style":451},[843],{"type":33,"value":563},{"type":27,"tag":422,"props":845,"children":846},{"style":836},[847],{"type":33,"value":848},"'public, s-maxage=300, stale-while-revalidate=600'",{"type":27,"tag":422,"props":850,"children":851},{"style":451},[852],{"type":33,"value":853},")\n",{"type":27,"tag":422,"props":855,"children":857},{"class":424,"line":856},19,[858],{"type":27,"tag":422,"props":859,"children":860},{"emptyLinePlaceholder":18},[861],{"type":33,"value":645},{"type":27,"tag":422,"props":863,"children":865},{"class":424,"line":864},20,[866,870,875,879,883,888],{"type":27,"tag":422,"props":867,"children":868},{"style":429},[869],{"type":33,"value":792},{"type":27,"tag":422,"props":871,"children":872},{"style":555},[873],{"type":33,"value":874}," cachedResponse",{"type":27,"tag":422,"props":876,"children":877},{"style":429},[878],{"type":33,"value":599},{"type":27,"tag":422,"props":880,"children":881},{"style":429},[882],{"type":33,"value":604},{"type":27,"tag":422,"props":884,"children":885},{"style":445},[886],{"type":33,"value":887}," Response",{"type":27,"tag":422,"props":889,"children":890},{"style":451},[891],{"type":33,"value":892},"(response.body, {\n",{"type":27,"tag":422,"props":894,"children":896},{"class":424,"line":895},21,[897],{"type":27,"tag":422,"props":898,"children":899},{"style":451},[900],{"type":33,"value":901},"      status: response.status,\n",{"type":27,"tag":422,"props":903,"children":905},{"class":424,"line":904},22,[906],{"type":27,"tag":422,"props":907,"children":908},{"style":451},[909],{"type":33,"value":910},"      headers,\n",{"type":27,"tag":422,"props":912,"children":914},{"class":424,"line":913},23,[915],{"type":27,"tag":422,"props":916,"children":917},{"style":451},[918],{"type":33,"value":919},"    })\n",{"type":27,"tag":422,"props":921,"children":923},{"class":424,"line":922},24,[924],{"type":27,"tag":422,"props":925,"children":926},{"emptyLinePlaceholder":18},[927],{"type":33,"value":645},{"type":27,"tag":422,"props":929,"children":931},{"class":424,"line":930},25,[932,937,942,947,952,957,962],{"type":27,"tag":422,"props":933,"children":934},{"style":451},[935],{"type":33,"value":936},"    context.",{"type":27,"tag":422,"props":938,"children":939},{"style":445},[940],{"type":33,"value":941},"waitUntil",{"type":27,"tag":422,"props":943,"children":944},{"style":451},[945],{"type":33,"value":946},"(cache.",{"type":27,"tag":422,"props":948,"children":949},{"style":445},[950],{"type":33,"value":951},"put",{"type":27,"tag":422,"props":953,"children":954},{"style":451},[955],{"type":33,"value":956},"(cacheKey, cachedResponse.",{"type":27,"tag":422,"props":958,"children":959},{"style":445},[960],{"type":33,"value":961},"clone",{"type":27,"tag":422,"props":963,"children":964},{"style":451},[965],{"type":33,"value":966},"()))\n",{"type":27,"tag":422,"props":968,"children":970},{"class":424,"line":969},26,[971,975],{"type":27,"tag":422,"props":972,"children":973},{"style":429},[974],{"type":33,"value":705},{"type":27,"tag":422,"props":976,"children":977},{"style":451},[978],{"type":33,"value":979}," cachedResponse\n",{"type":27,"tag":422,"props":981,"children":983},{"class":424,"line":982},27,[984],{"type":27,"tag":422,"props":985,"children":986},{"style":451},[987],{"type":33,"value":719},{"type":27,"tag":422,"props":989,"children":991},{"class":424,"line":990},28,[992],{"type":27,"tag":422,"props":993,"children":994},{"emptyLinePlaceholder":18},[995],{"type":33,"value":645},{"type":27,"tag":422,"props":997,"children":999},{"class":424,"line":998},29,[1000,1005],{"type":27,"tag":422,"props":1001,"children":1002},{"style":429},[1003],{"type":33,"value":1004},"  return",{"type":27,"tag":422,"props":1006,"children":1007},{"style":451},[1008],{"type":33,"value":1009}," response\n",{"type":27,"tag":422,"props":1011,"children":1013},{"class":424,"line":1012},30,[1014],{"type":27,"tag":422,"props":1015,"children":1016},{"style":451},[1017],{"type":33,"value":1018},"}\n",{"type":27,"tag":35,"props":1020,"children":1021},{},[1022,1024],{"type":33,"value":1023},"这个例子并不复杂，但它说明了边缘最有价值的一点：",{"type":27,"tag":93,"props":1025,"children":1026},{},[1027],{"type":33,"value":1028},"高频重复请求，尽量别老往中心打。",{"type":27,"tag":99,"props":1030,"children":1031},{},[],{"type":27,"tag":103,"props":1033,"children":1035},{"id":1034},"_6-ttfb-真正下降通常要靠三件事一起发生",[1036],{"type":33,"value":1037},"6. TTFB 真正下降，通常要靠三件事一起发生",{"type":27,"tag":166,"props":1039,"children":1041},{"id":1040},"_61-页面壳体能就近返回",[1042],{"type":33,"value":1043},"6.1 页面壳体能就近返回",{"type":27,"tag":35,"props":1045,"children":1046},{},[1047],{"type":33,"value":1048},"如果 HTML 或关键片段能在边缘直接命中，首字节自然会更早到。",{"type":27,"tag":166,"props":1050,"children":1052},{"id":1051},"_62-回源次数被减少",[1053],{"type":33,"value":1054},"6.2 回源次数被减少",{"type":27,"tag":35,"props":1056,"children":1057},{},[1058],{"type":33,"value":1059},"边缘最怕“看似部署在全球，实则每次都回家问一遍”。",{"type":27,"tag":166,"props":1061,"children":1063},{"id":1062},"_63-回源内容被做成更高命中率的结果",[1064],{"type":33,"value":1065},"6.3 回源内容被做成更高命中率的结果",{"type":27,"tag":35,"props":1067,"children":1068},{},[1069],{"type":33,"value":1070},"很多接口不适合用户级缓存，但适合做区域级、语言级、活动级缓存。缓存粒度设计得好，边缘价值才出来。",{"type":27,"tag":99,"props":1072,"children":1073},{},[],{"type":27,"tag":103,"props":1075,"children":1077},{"id":1076},"_7-做边缘项目最容易低估的是观测成本",[1078],{"type":33,"value":1079},"7. 做边缘项目，最容易低估的是观测成本",{"type":27,"tag":35,"props":1081,"children":1082},{},[1083],{"type":33,"value":1084},"边缘把逻辑拉近用户，也把问题分散到了全球。",{"type":27,"tag":35,"props":1086,"children":1087},{},[1088],{"type":33,"value":1089},"因此你至少要有：",{"type":27,"tag":55,"props":1091,"children":1092},{},[1093,1098,1103,1108],{"type":27,"tag":59,"props":1094,"children":1095},{},[1096],{"type":33,"value":1097},"区域维度的命中率指标",{"type":27,"tag":59,"props":1099,"children":1100},{},[1101],{"type":33,"value":1102},"回源率和回源耗时",{"type":27,"tag":59,"props":1104,"children":1105},{},[1106],{"type":33,"value":1107},"函数错误日志和超时记录",{"type":27,"tag":59,"props":1109,"children":1110},{},[1111],{"type":33,"value":1112},"关键页面在不同国家的 TTFB 采样",{"type":27,"tag":35,"props":1114,"children":1115},{},[1116],{"type":33,"value":1117},"否则你只能知道“有时候很快”，却不知道“哪里还在慢”。",{"type":27,"tag":99,"props":1119,"children":1120},{},[],{"type":27,"tag":103,"props":1122,"children":1124},{"id":1123},"_8-关于成本的一个清醒判断",[1125],{"type":33,"value":1126},"8. 关于成本的一个清醒判断",{"type":27,"tag":35,"props":1128,"children":1129},{},[1130],{"type":33,"value":1131},"边缘计算的价值，不只是省几百毫秒，而是把高频流量拦在更便宜、更稳定的地方。",{"type":27,"tag":35,"props":1133,"children":1134},{},[1135],{"type":33,"value":1136},"但它也会带来新的管理成本：",{"type":27,"tag":55,"props":1138,"children":1139},{},[1140,1145,1150],{"type":27,"tag":59,"props":1141,"children":1142},{},[1143],{"type":33,"value":1144},"缓存失效更复杂",{"type":27,"tag":59,"props":1146,"children":1147},{},[1148],{"type":33,"value":1149},"调试链路更长",{"type":27,"tag":59,"props":1151,"children":1152},{},[1153],{"type":33,"value":1154},"不同区域行为差异更难定位",{"type":27,"tag":35,"props":1156,"children":1157},{},[1158],{"type":33,"value":1159},"所以判断是否值得，不要只看技术酷不酷，要看：",{"type":27,"tag":133,"props":1161,"children":1162},{},[1163,1168,1173],{"type":27,"tag":59,"props":1164,"children":1165},{},[1166],{"type":33,"value":1167},"你的用户是否跨地区明显分布",{"type":27,"tag":59,"props":1169,"children":1170},{},[1171],{"type":33,"value":1172},"你的内容是否足够缓存友好",{"type":27,"tag":59,"props":1174,"children":1175},{},[1176],{"type":33,"value":1177},"你的团队是否有能力经营缓存策略与观测体系",{"type":27,"tag":99,"props":1179,"children":1180},{},[],{"type":27,"tag":103,"props":1182,"children":1184},{"id":1183},"总结",[1185],{"type":33,"value":1183},{"type":27,"tag":55,"props":1187,"children":1188},{},[1189,1194,1199,1204],{"type":27,"tag":59,"props":1190,"children":1191},{},[1192],{"type":33,"value":1193},"Cloudflare Pages 和边缘函数最擅长的是缩短网络距离、提升缓存命中、下沉轻逻辑。",{"type":27,"tag":59,"props":1195,"children":1196},{},[1197],{"type":33,"value":1198},"真正的复杂业务仍应留在中心应用和数据层。",{"type":27,"tag":59,"props":1200,"children":1201},{},[1202],{"type":33,"value":1203},"边缘不是万能加速器，而是一次职责重新分配。",{"type":27,"tag":59,"props":1205,"children":1206},{},[1207],{"type":33,"value":1208},"做得好，TTFB 会明显改善；做不好，只是把复杂度搬到了更远的地方。",{"type":27,"tag":35,"props":1210,"children":1211},{},[1212],{"type":33,"value":1213},"小明收尾一句：",{"type":27,"tag":41,"props":1215,"children":1216},{},[1217],{"type":27,"tag":35,"props":1218,"children":1219},{},[1220],{"type":33,"value":1221},"边缘的本质，不是把所有东西都搬到前线，而是让真正值得提前处理的事情，别再排队排到总部去。",{"type":27,"tag":1223,"props":1224,"children":1225},"style",{},[1226],{"type":33,"value":1227},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":20,"depth":20,"links":1229},[1230,1231,1236,1237,1238,1239,1244,1245,1246],{"id":105,"depth":473,"text":108},{"id":161,"depth":473,"text":164,"children":1232},[1233,1234,1235],{"id":168,"depth":20,"text":171},{"id":184,"depth":20,"text":187},{"id":218,"depth":20,"text":221},{"id":255,"depth":473,"text":258},{"id":300,"depth":473,"text":303},{"id":406,"depth":473,"text":409},{"id":1034,"depth":473,"text":1037,"children":1240},[1241,1242,1243],{"id":1040,"depth":20,"text":1043},{"id":1051,"depth":20,"text":1054},{"id":1062,"depth":20,"text":1065},{"id":1076,"depth":473,"text":1079},{"id":1123,"depth":473,"text":1126},{"id":1183,"depth":473,"text":1183},"markdown","content:topics:engineering:cloudflare-pages-edge-computing-guide.md","content","topics/engineering/cloudflare-pages-edge-computing-guide.md","topics/engineering/cloudflare-pages-edge-computing-guide","md",1777109940292]