[{"data":1,"prerenderedAt":2902},["ShallowReactive",2],{"article-alternates":3,"article-\u002Fit\u002Ftech\u002Fedge-ssr-ridurre-latenza-personalizzazione-40ms":13},{"i18nKey":4,"paths":5},"tech-003-2026-07",{"de":6,"en":7,"es":8,"fr":9,"it":10,"ru":11,"tr":12},"\u002Fde\u002Ftech\u002Fedge-ssr-personalisierung-40ms-latenz","\u002Fen\u002Ftech\u002Fedge-ssr-personalization-latency-40ms","\u002Fes\u002Ftech\u002Freducir-latencia-personalizacion-edge-ssr-40ms","\u002Ffr\u002Ftech\u002Fedge-ssr-personnalisation-latence-40ms","\u002Fit\u002Ftech\u002Fedge-ssr-ridurre-latenza-personalizzazione-40ms","\u002Fru\u002Ftech\u002Freducir-latencia-personalizacion-40ms-edge-ssr","\u002Ftr\u002Ftech\u002Fedge-ssr-ile-personalizasyon-latencysini-40msye-dusurmek",{"_path":10,"_dir":14,"_draft":15,"_partial":15,"_locale":16,"title":17,"description":18,"publishedAt":19,"modifiedAt":19,"category":14,"i18nKey":4,"tags":20,"readingTime":26,"author":27,"body":28,"_type":2896,"_id":2897,"_source":2898,"_file":2899,"_stem":2900,"_extension":2901},"tech",false,"","Ridurre la Latenza della Personalizzazione SSR a 40ms con Edge Computing","Architettura KV store con Cloudflare Workers e Vercel Edge per abbassare la personalizzazione SSR da 200ms a 40ms in produzione.","2026-07-28",[21,22,23,24,25],"edge-ssr","cloudflare-workers","vercel-edge","kv-store","web-performance",9,"Roibase",{"type":29,"children":30,"toc":2886},"root",[31,39,46,51,56,61,67,72,920,929,961,966,973,978,1470,1475,1481,1525,1533,1546,1559,1593,1603,1609,1614,1624,1944,1954,2266,2271,2277,2293,2298,2766,2771,2781,2787,2792,2800,2865,2875,2880],{"type":32,"tag":33,"props":34,"children":35},"element","p",{},[36],{"type":37,"value":38},"text","Nel 2026, la personalizzazione SSR mantiene costi elevati: trasporta il contesto utente al server di origine, interroga il database, esegui il rendering, restituisci tramite CDN. Latenza media 200-300ms. L'Edge SSR elimina questo ciclo — preleva i dati dal KV store nel punto più vicino all'utente, esegui il rendering, restituisci. L'architettura dietro una latenza di 40ms in produzione? Scopriamo come funziona.",{"type":32,"tag":40,"props":41,"children":43},"h2",{"id":42},"leconomia-della-edge-ssr",[44],{"type":37,"value":45},"L'Economia della Edge SSR",{"type":32,"tag":33,"props":47,"children":48},{},[49],{"type":37,"value":50},"Nel modello origin-based SSR, ogni request segue lo stesso percorso: edge CDN → server di origine → database → logica applicativa → risposta. L'utente potrebbe essere a 50ms di distanza, ma se l'origine si trova a Istanbul e il database a Francoforte, il round-trip inizia da 180ms. L'Edge SSR inverte questa economia: Cloudflare Workers o Vercel Edge Functions eseguono codice nel PoP (Point of Presence) a 15-30ms dall'utente. Quando il key-value store risiede nella stessa posizione edge, la latenza totale scende a 40-60ms.",{"type":32,"tag":33,"props":52,"children":53},{},[54],{"type":37,"value":55},"Il guadagno non è solo temporale — cala anche il costo delle risorse. Utilizzi il server di origine solo per le mutazioni (POST\u002FPUT\u002FDELETE); il 90% del traffico GET si chiude direttamente in edge. Il cold start su Vercel Edge è 0-5ms, su Cloudflare Workers mediamente 1ms. In una configurazione SSR tradizionale, il cold start di un container Node.js oscilla tra 500-1200ms. Questa differenza impatta direttamente sulla velocità della prima interazione.",{"type":32,"tag":33,"props":57,"children":58},{},[59],{"type":37,"value":60},"In un sito di e-commerce, puoi eseguire il rendering di elementi personalizzati in edge — prezzi specifici per utente, disponibilità di stock, contenuto del carrello. Metti in cache lo scheletro della pagina principale come HTML statico e compila solo i blocchi dinamici tramite edge SSR — logica di \"progressive enhancement\". Questo approccio ibrido, quando il cache hit rate raggiunge l'85%, riduce il TTFB (Time to First Byte) a 30ms.",{"type":32,"tag":40,"props":62,"children":64},{"id":63},"architettura-cloudflare-workers-kv-store",[65],{"type":37,"value":66},"Architettura Cloudflare Workers + KV Store",{"type":32,"tag":33,"props":68,"children":69},{},[70],{"type":37,"value":71},"Cloudflare Workers si basa su isolate V8 — a differenza dei container tradizionali, ogni request viene eseguita in una sandbox separata senza stato condiviso. Il KV store è un archivio eventually-consistent, replicato globalmente. Obiettivi di latenza: lettura 10-30ms, scrittura 100-200ms (a causa della replica asincrona). Setup:",{"type":32,"tag":73,"props":74,"children":78},"pre",{"className":75,"code":76,"language":77,"meta":16,"style":16},"language-javascript shiki shiki-themes github-dark","\u002F\u002F worker.js — Entry point per Edge SSR\nexport default {\n  async fetch(request, env) {\n    const url = new URL(request.url);\n    const userId = getUserId(request); \u002F\u002F Estrai dal cookie\n\n    \u002F\u002F Recupera contesto utente da KV\n    const userCtx = await env.USER_KV.get(`user:${userId}`, { type: 'json' });\n    \n    if (!userCtx) {\n      return new Response('Unauthorized', { status: 401 });\n    }\n\n    \u002F\u002F Renderizza pagina personalizzata\n    const html = renderPersonalizedPage({\n      userName: userCtx.name,\n      cart: userCtx.cart,\n      recentlyViewed: userCtx.recentlyViewed,\n    });\n\n    return new Response(html, {\n      headers: {\n        'Content-Type': 'text\u002Fhtml;charset=UTF-8',\n        'Cache-Control': 'private, max-age=0',\n      },\n    });\n  },\n};\n\nfunction renderPersonalizedPage(data) {\n  \u002F\u002F Logica template semplice — in produzione usa Vue\u002FReact render\n  return `\n    \u003C!DOCTYPE html>\n    \u003Chtml>\n      \u003Chead>\u003Ctitle>Benvenuto ${data.userName}\u003C\u002Ftitle>\u003C\u002Fhead>\n      \u003Cbody>\n        \u003Ch1>Ciao ${data.userName}\u003C\u002Fh1>\n        \u003Cp>Hai ${data.cart.length} articoli nel carrello\u003C\u002Fp>\n        \u003Cul>\n          ${data.recentlyViewed.map(p => `\u003Cli>${p}\u003C\u002Fli>`).join('')}\n        \u003C\u002Ful>\n      \u003C\u002Fbody>\n    \u003C\u002Fhtml>\n  `;\n}\n","javascript",[79],{"type":32,"tag":80,"props":81,"children":82},"code",{"__ignoreMap":16},[83,95,116,157,192,224,234,243,320,328,352,393,402,410,419,446,455,464,473,482,490,512,521,545,567,576,584,593,602,610,636,645,659,668,677,704,713,739,775,784,871,880,889,898,912],{"type":32,"tag":84,"props":85,"children":88},"span",{"class":86,"line":87},"line",1,[89],{"type":32,"tag":84,"props":90,"children":92},{"style":91},"--shiki-default:#6A737D",[93],{"type":37,"value":94},"\u002F\u002F worker.js — Entry point per Edge SSR\n",{"type":32,"tag":84,"props":96,"children":98},{"class":86,"line":97},2,[99,105,110],{"type":32,"tag":84,"props":100,"children":102},{"style":101},"--shiki-default:#F97583",[103],{"type":37,"value":104},"export",{"type":32,"tag":84,"props":106,"children":107},{"style":101},[108],{"type":37,"value":109}," default",{"type":32,"tag":84,"props":111,"children":113},{"style":112},"--shiki-default:#E1E4E8",[114],{"type":37,"value":115}," {\n",{"type":32,"tag":84,"props":117,"children":119},{"class":86,"line":118},3,[120,125,131,136,142,147,152],{"type":32,"tag":84,"props":121,"children":122},{"style":101},[123],{"type":37,"value":124},"  async",{"type":32,"tag":84,"props":126,"children":128},{"style":127},"--shiki-default:#B392F0",[129],{"type":37,"value":130}," fetch",{"type":32,"tag":84,"props":132,"children":133},{"style":112},[134],{"type":37,"value":135},"(",{"type":32,"tag":84,"props":137,"children":139},{"style":138},"--shiki-default:#FFAB70",[140],{"type":37,"value":141},"request",{"type":32,"tag":84,"props":143,"children":144},{"style":112},[145],{"type":37,"value":146},", ",{"type":32,"tag":84,"props":148,"children":149},{"style":138},[150],{"type":37,"value":151},"env",{"type":32,"tag":84,"props":153,"children":154},{"style":112},[155],{"type":37,"value":156},") {\n",{"type":32,"tag":84,"props":158,"children":160},{"class":86,"line":159},4,[161,166,172,177,182,187],{"type":32,"tag":84,"props":162,"children":163},{"style":101},[164],{"type":37,"value":165},"    const",{"type":32,"tag":84,"props":167,"children":169},{"style":168},"--shiki-default:#79B8FF",[170],{"type":37,"value":171}," url",{"type":32,"tag":84,"props":173,"children":174},{"style":101},[175],{"type":37,"value":176}," =",{"type":32,"tag":84,"props":178,"children":179},{"style":101},[180],{"type":37,"value":181}," new",{"type":32,"tag":84,"props":183,"children":184},{"style":127},[185],{"type":37,"value":186}," URL",{"type":32,"tag":84,"props":188,"children":189},{"style":112},[190],{"type":37,"value":191},"(request.url);\n",{"type":32,"tag":84,"props":193,"children":195},{"class":86,"line":194},5,[196,200,205,209,214,219],{"type":32,"tag":84,"props":197,"children":198},{"style":101},[199],{"type":37,"value":165},{"type":32,"tag":84,"props":201,"children":202},{"style":168},[203],{"type":37,"value":204}," userId",{"type":32,"tag":84,"props":206,"children":207},{"style":101},[208],{"type":37,"value":176},{"type":32,"tag":84,"props":210,"children":211},{"style":127},[212],{"type":37,"value":213}," getUserId",{"type":32,"tag":84,"props":215,"children":216},{"style":112},[217],{"type":37,"value":218},"(request); ",{"type":32,"tag":84,"props":220,"children":221},{"style":91},[222],{"type":37,"value":223},"\u002F\u002F Estrai dal cookie\n",{"type":32,"tag":84,"props":225,"children":227},{"class":86,"line":226},6,[228],{"type":32,"tag":84,"props":229,"children":231},{"emptyLinePlaceholder":230},true,[232],{"type":37,"value":233},"\n",{"type":32,"tag":84,"props":235,"children":237},{"class":86,"line":236},7,[238],{"type":32,"tag":84,"props":239,"children":240},{"style":91},[241],{"type":37,"value":242},"    \u002F\u002F Recupera contesto utente da KV\n",{"type":32,"tag":84,"props":244,"children":246},{"class":86,"line":245},8,[247,251,256,260,265,270,275,280,285,289,295,300,305,310,315],{"type":32,"tag":84,"props":248,"children":249},{"style":101},[250],{"type":37,"value":165},{"type":32,"tag":84,"props":252,"children":253},{"style":168},[254],{"type":37,"value":255}," userCtx",{"type":32,"tag":84,"props":257,"children":258},{"style":101},[259],{"type":37,"value":176},{"type":32,"tag":84,"props":261,"children":262},{"style":101},[263],{"type":37,"value":264}," await",{"type":32,"tag":84,"props":266,"children":267},{"style":112},[268],{"type":37,"value":269}," env.",{"type":32,"tag":84,"props":271,"children":272},{"style":168},[273],{"type":37,"value":274},"USER_KV",{"type":32,"tag":84,"props":276,"children":277},{"style":112},[278],{"type":37,"value":279},".",{"type":32,"tag":84,"props":281,"children":282},{"style":127},[283],{"type":37,"value":284},"get",{"type":32,"tag":84,"props":286,"children":287},{"style":112},[288],{"type":37,"value":135},{"type":32,"tag":84,"props":290,"children":292},{"style":291},"--shiki-default:#9ECBFF",[293],{"type":37,"value":294},"`user:${",{"type":32,"tag":84,"props":296,"children":297},{"style":112},[298],{"type":37,"value":299},"userId",{"type":32,"tag":84,"props":301,"children":302},{"style":291},[303],{"type":37,"value":304},"}`",{"type":32,"tag":84,"props":306,"children":307},{"style":112},[308],{"type":37,"value":309},", { type: ",{"type":32,"tag":84,"props":311,"children":312},{"style":291},[313],{"type":37,"value":314},"'json'",{"type":32,"tag":84,"props":316,"children":317},{"style":112},[318],{"type":37,"value":319}," });\n",{"type":32,"tag":84,"props":321,"children":322},{"class":86,"line":26},[323],{"type":32,"tag":84,"props":324,"children":325},{"style":112},[326],{"type":37,"value":327},"    \n",{"type":32,"tag":84,"props":329,"children":331},{"class":86,"line":330},10,[332,337,342,347],{"type":32,"tag":84,"props":333,"children":334},{"style":101},[335],{"type":37,"value":336},"    if",{"type":32,"tag":84,"props":338,"children":339},{"style":112},[340],{"type":37,"value":341}," (",{"type":32,"tag":84,"props":343,"children":344},{"style":101},[345],{"type":37,"value":346},"!",{"type":32,"tag":84,"props":348,"children":349},{"style":112},[350],{"type":37,"value":351},"userCtx) {\n",{"type":32,"tag":84,"props":353,"children":355},{"class":86,"line":354},11,[356,361,365,370,374,379,384,389],{"type":32,"tag":84,"props":357,"children":358},{"style":101},[359],{"type":37,"value":360},"      return",{"type":32,"tag":84,"props":362,"children":363},{"style":101},[364],{"type":37,"value":181},{"type":32,"tag":84,"props":366,"children":367},{"style":127},[368],{"type":37,"value":369}," Response",{"type":32,"tag":84,"props":371,"children":372},{"style":112},[373],{"type":37,"value":135},{"type":32,"tag":84,"props":375,"children":376},{"style":291},[377],{"type":37,"value":378},"'Unauthorized'",{"type":32,"tag":84,"props":380,"children":381},{"style":112},[382],{"type":37,"value":383},", { status: ",{"type":32,"tag":84,"props":385,"children":386},{"style":168},[387],{"type":37,"value":388},"401",{"type":32,"tag":84,"props":390,"children":391},{"style":112},[392],{"type":37,"value":319},{"type":32,"tag":84,"props":394,"children":396},{"class":86,"line":395},12,[397],{"type":32,"tag":84,"props":398,"children":399},{"style":112},[400],{"type":37,"value":401},"    }\n",{"type":32,"tag":84,"props":403,"children":405},{"class":86,"line":404},13,[406],{"type":32,"tag":84,"props":407,"children":408},{"emptyLinePlaceholder":230},[409],{"type":37,"value":233},{"type":32,"tag":84,"props":411,"children":413},{"class":86,"line":412},14,[414],{"type":32,"tag":84,"props":415,"children":416},{"style":91},[417],{"type":37,"value":418},"    \u002F\u002F Renderizza pagina personalizzata\n",{"type":32,"tag":84,"props":420,"children":422},{"class":86,"line":421},15,[423,427,432,436,441],{"type":32,"tag":84,"props":424,"children":425},{"style":101},[426],{"type":37,"value":165},{"type":32,"tag":84,"props":428,"children":429},{"style":168},[430],{"type":37,"value":431}," html",{"type":32,"tag":84,"props":433,"children":434},{"style":101},[435],{"type":37,"value":176},{"type":32,"tag":84,"props":437,"children":438},{"style":127},[439],{"type":37,"value":440}," renderPersonalizedPage",{"type":32,"tag":84,"props":442,"children":443},{"style":112},[444],{"type":37,"value":445},"({\n",{"type":32,"tag":84,"props":447,"children":449},{"class":86,"line":448},16,[450],{"type":32,"tag":84,"props":451,"children":452},{"style":112},[453],{"type":37,"value":454},"      userName: userCtx.name,\n",{"type":32,"tag":84,"props":456,"children":458},{"class":86,"line":457},17,[459],{"type":32,"tag":84,"props":460,"children":461},{"style":112},[462],{"type":37,"value":463},"      cart: userCtx.cart,\n",{"type":32,"tag":84,"props":465,"children":467},{"class":86,"line":466},18,[468],{"type":32,"tag":84,"props":469,"children":470},{"style":112},[471],{"type":37,"value":472},"      recentlyViewed: userCtx.recentlyViewed,\n",{"type":32,"tag":84,"props":474,"children":476},{"class":86,"line":475},19,[477],{"type":32,"tag":84,"props":478,"children":479},{"style":112},[480],{"type":37,"value":481},"    });\n",{"type":32,"tag":84,"props":483,"children":485},{"class":86,"line":484},20,[486],{"type":32,"tag":84,"props":487,"children":488},{"emptyLinePlaceholder":230},[489],{"type":37,"value":233},{"type":32,"tag":84,"props":491,"children":493},{"class":86,"line":492},21,[494,499,503,507],{"type":32,"tag":84,"props":495,"children":496},{"style":101},[497],{"type":37,"value":498},"    return",{"type":32,"tag":84,"props":500,"children":501},{"style":101},[502],{"type":37,"value":181},{"type":32,"tag":84,"props":504,"children":505},{"style":127},[506],{"type":37,"value":369},{"type":32,"tag":84,"props":508,"children":509},{"style":112},[510],{"type":37,"value":511},"(html, {\n",{"type":32,"tag":84,"props":513,"children":515},{"class":86,"line":514},22,[516],{"type":32,"tag":84,"props":517,"children":518},{"style":112},[519],{"type":37,"value":520},"      headers: {\n",{"type":32,"tag":84,"props":522,"children":524},{"class":86,"line":523},23,[525,530,535,540],{"type":32,"tag":84,"props":526,"children":527},{"style":291},[528],{"type":37,"value":529},"        'Content-Type'",{"type":32,"tag":84,"props":531,"children":532},{"style":112},[533],{"type":37,"value":534},": ",{"type":32,"tag":84,"props":536,"children":537},{"style":291},[538],{"type":37,"value":539},"'text\u002Fhtml;charset=UTF-8'",{"type":32,"tag":84,"props":541,"children":542},{"style":112},[543],{"type":37,"value":544},",\n",{"type":32,"tag":84,"props":546,"children":548},{"class":86,"line":547},24,[549,554,558,563],{"type":32,"tag":84,"props":550,"children":551},{"style":291},[552],{"type":37,"value":553},"        'Cache-Control'",{"type":32,"tag":84,"props":555,"children":556},{"style":112},[557],{"type":37,"value":534},{"type":32,"tag":84,"props":559,"children":560},{"style":291},[561],{"type":37,"value":562},"'private, max-age=0'",{"type":32,"tag":84,"props":564,"children":565},{"style":112},[566],{"type":37,"value":544},{"type":32,"tag":84,"props":568,"children":570},{"class":86,"line":569},25,[571],{"type":32,"tag":84,"props":572,"children":573},{"style":112},[574],{"type":37,"value":575},"      },\n",{"type":32,"tag":84,"props":577,"children":579},{"class":86,"line":578},26,[580],{"type":32,"tag":84,"props":581,"children":582},{"style":112},[583],{"type":37,"value":481},{"type":32,"tag":84,"props":585,"children":587},{"class":86,"line":586},27,[588],{"type":32,"tag":84,"props":589,"children":590},{"style":112},[591],{"type":37,"value":592},"  },\n",{"type":32,"tag":84,"props":594,"children":596},{"class":86,"line":595},28,[597],{"type":32,"tag":84,"props":598,"children":599},{"style":112},[600],{"type":37,"value":601},"};\n",{"type":32,"tag":84,"props":603,"children":605},{"class":86,"line":604},29,[606],{"type":32,"tag":84,"props":607,"children":608},{"emptyLinePlaceholder":230},[609],{"type":37,"value":233},{"type":32,"tag":84,"props":611,"children":613},{"class":86,"line":612},30,[614,619,623,627,632],{"type":32,"tag":84,"props":615,"children":616},{"style":101},[617],{"type":37,"value":618},"function",{"type":32,"tag":84,"props":620,"children":621},{"style":127},[622],{"type":37,"value":440},{"type":32,"tag":84,"props":624,"children":625},{"style":112},[626],{"type":37,"value":135},{"type":32,"tag":84,"props":628,"children":629},{"style":138},[630],{"type":37,"value":631},"data",{"type":32,"tag":84,"props":633,"children":634},{"style":112},[635],{"type":37,"value":156},{"type":32,"tag":84,"props":637,"children":639},{"class":86,"line":638},31,[640],{"type":32,"tag":84,"props":641,"children":642},{"style":91},[643],{"type":37,"value":644},"  \u002F\u002F Logica template semplice — in produzione usa Vue\u002FReact render\n",{"type":32,"tag":84,"props":646,"children":648},{"class":86,"line":647},32,[649,654],{"type":32,"tag":84,"props":650,"children":651},{"style":101},[652],{"type":37,"value":653},"  return",{"type":32,"tag":84,"props":655,"children":656},{"style":291},[657],{"type":37,"value":658}," `\n",{"type":32,"tag":84,"props":660,"children":662},{"class":86,"line":661},33,[663],{"type":32,"tag":84,"props":664,"children":665},{"style":291},[666],{"type":37,"value":667},"    \u003C!DOCTYPE html>\n",{"type":32,"tag":84,"props":669,"children":671},{"class":86,"line":670},34,[672],{"type":32,"tag":84,"props":673,"children":674},{"style":291},[675],{"type":37,"value":676},"    \u003Chtml>\n",{"type":32,"tag":84,"props":678,"children":680},{"class":86,"line":679},35,[681,686,690,694,699],{"type":32,"tag":84,"props":682,"children":683},{"style":291},[684],{"type":37,"value":685},"      \u003Chead>\u003Ctitle>Benvenuto ${",{"type":32,"tag":84,"props":687,"children":688},{"style":112},[689],{"type":37,"value":631},{"type":32,"tag":84,"props":691,"children":692},{"style":291},[693],{"type":37,"value":279},{"type":32,"tag":84,"props":695,"children":696},{"style":112},[697],{"type":37,"value":698},"userName",{"type":32,"tag":84,"props":700,"children":701},{"style":291},[702],{"type":37,"value":703},"}\u003C\u002Ftitle>\u003C\u002Fhead>\n",{"type":32,"tag":84,"props":705,"children":707},{"class":86,"line":706},36,[708],{"type":32,"tag":84,"props":709,"children":710},{"style":291},[711],{"type":37,"value":712},"      \u003Cbody>\n",{"type":32,"tag":84,"props":714,"children":716},{"class":86,"line":715},37,[717,722,726,730,734],{"type":32,"tag":84,"props":718,"children":719},{"style":291},[720],{"type":37,"value":721},"        \u003Ch1>Ciao ${",{"type":32,"tag":84,"props":723,"children":724},{"style":112},[725],{"type":37,"value":631},{"type":32,"tag":84,"props":727,"children":728},{"style":291},[729],{"type":37,"value":279},{"type":32,"tag":84,"props":731,"children":732},{"style":112},[733],{"type":37,"value":698},{"type":32,"tag":84,"props":735,"children":736},{"style":291},[737],{"type":37,"value":738},"}\u003C\u002Fh1>\n",{"type":32,"tag":84,"props":740,"children":742},{"class":86,"line":741},38,[743,748,752,756,761,765,770],{"type":32,"tag":84,"props":744,"children":745},{"style":291},[746],{"type":37,"value":747},"        \u003Cp>Hai ${",{"type":32,"tag":84,"props":749,"children":750},{"style":112},[751],{"type":37,"value":631},{"type":32,"tag":84,"props":753,"children":754},{"style":291},[755],{"type":37,"value":279},{"type":32,"tag":84,"props":757,"children":758},{"style":112},[759],{"type":37,"value":760},"cart",{"type":32,"tag":84,"props":762,"children":763},{"style":291},[764],{"type":37,"value":279},{"type":32,"tag":84,"props":766,"children":767},{"style":168},[768],{"type":37,"value":769},"length",{"type":32,"tag":84,"props":771,"children":772},{"style":291},[773],{"type":37,"value":774},"} articoli nel carrello\u003C\u002Fp>\n",{"type":32,"tag":84,"props":776,"children":778},{"class":86,"line":777},39,[779],{"type":32,"tag":84,"props":780,"children":781},{"style":291},[782],{"type":37,"value":783},"        \u003Cul>\n",{"type":32,"tag":84,"props":785,"children":787},{"class":86,"line":786},40,[788,793,797,801,806,810,815,819,823,828,833,837,842,847,852,856,861,866],{"type":32,"tag":84,"props":789,"children":790},{"style":291},[791],{"type":37,"value":792},"          ${",{"type":32,"tag":84,"props":794,"children":795},{"style":112},[796],{"type":37,"value":631},{"type":32,"tag":84,"props":798,"children":799},{"style":291},[800],{"type":37,"value":279},{"type":32,"tag":84,"props":802,"children":803},{"style":112},[804],{"type":37,"value":805},"recentlyViewed",{"type":32,"tag":84,"props":807,"children":808},{"style":291},[809],{"type":37,"value":279},{"type":32,"tag":84,"props":811,"children":812},{"style":127},[813],{"type":37,"value":814},"map",{"type":32,"tag":84,"props":816,"children":817},{"style":291},[818],{"type":37,"value":135},{"type":32,"tag":84,"props":820,"children":821},{"style":168},[822],{"type":37,"value":33},{"type":32,"tag":84,"props":824,"children":825},{"style":101},[826],{"type":37,"value":827}," =>",{"type":32,"tag":84,"props":829,"children":830},{"style":291},[831],{"type":37,"value":832}," `\u003Cli>${",{"type":32,"tag":84,"props":834,"children":835},{"style":112},[836],{"type":37,"value":33},{"type":32,"tag":84,"props":838,"children":839},{"style":291},[840],{"type":37,"value":841},"}\u003C\u002Fli>`",{"type":32,"tag":84,"props":843,"children":844},{"style":291},[845],{"type":37,"value":846},").",{"type":32,"tag":84,"props":848,"children":849},{"style":127},[850],{"type":37,"value":851},"join",{"type":32,"tag":84,"props":853,"children":854},{"style":291},[855],{"type":37,"value":135},{"type":32,"tag":84,"props":857,"children":858},{"style":291},[859],{"type":37,"value":860},"''",{"type":32,"tag":84,"props":862,"children":863},{"style":291},[864],{"type":37,"value":865},")",{"type":32,"tag":84,"props":867,"children":868},{"style":291},[869],{"type":37,"value":870},"}\n",{"type":32,"tag":84,"props":872,"children":874},{"class":86,"line":873},41,[875],{"type":32,"tag":84,"props":876,"children":877},{"style":291},[878],{"type":37,"value":879},"        \u003C\u002Ful>\n",{"type":32,"tag":84,"props":881,"children":883},{"class":86,"line":882},42,[884],{"type":32,"tag":84,"props":885,"children":886},{"style":291},[887],{"type":37,"value":888},"      \u003C\u002Fbody>\n",{"type":32,"tag":84,"props":890,"children":892},{"class":86,"line":891},43,[893],{"type":32,"tag":84,"props":894,"children":895},{"style":291},[896],{"type":37,"value":897},"    \u003C\u002Fhtml>\n",{"type":32,"tag":84,"props":899,"children":901},{"class":86,"line":900},44,[902,907],{"type":32,"tag":84,"props":903,"children":904},{"style":291},[905],{"type":37,"value":906},"  `",{"type":32,"tag":84,"props":908,"children":909},{"style":112},[910],{"type":37,"value":911},";\n",{"type":32,"tag":84,"props":913,"children":915},{"class":86,"line":914},45,[916],{"type":32,"tag":84,"props":917,"children":918},{"style":112},[919],{"type":37,"value":870},{"type":32,"tag":33,"props":921,"children":922},{},[923],{"type":32,"tag":924,"props":925,"children":926},"strong",{},[927],{"type":37,"value":928},"Struttura dati KV:",{"type":32,"tag":930,"props":931,"children":932},"ul",{},[933,945,956],{"type":32,"tag":934,"props":935,"children":936},"li",{},[937,939],{"type":37,"value":938},"Key: ",{"type":32,"tag":80,"props":940,"children":942},{"className":941},[],[943],{"type":37,"value":944},"user:{userId}",{"type":32,"tag":934,"props":946,"children":947},{},[948,950],{"type":37,"value":949},"Value: JSON — ",{"type":32,"tag":80,"props":951,"children":953},{"className":952},[],[954],{"type":37,"value":955},"{ name, cart, recentlyViewed, priceTier }",{"type":32,"tag":934,"props":957,"children":958},{},[959],{"type":37,"value":960},"TTL: 3600s (cache per 1 ora, poi refresh dall'origine)",{"type":32,"tag":33,"props":962,"children":963},{},[964],{"type":37,"value":965},"Con questo setup, ogni lettura impiega 15-25ms — nessun salto di rete verso il Postgres a Francoforte. Il percorso di scrittura è diverso: quando arriva una mutazione, invia una POST all'API di origine, che aggiorna sia il database che scrive in KV in modo asincrono. Poiché la coerenza del KV è \"eventual\", i nuovi dati appaiono su tutti i nodi edge entro 100ms dalla scrittura.",{"type":32,"tag":967,"props":968,"children":970},"h3",{"id":969},"alternativa-vercel-edge-functions",[971],{"type":37,"value":972},"Alternativa: Vercel Edge Functions",{"type":32,"tag":33,"props":974,"children":975},{},[976],{"type":37,"value":977},"Vercel Edge si integra nativamente con Next.js — funziona come middleware. Setup:",{"type":32,"tag":73,"props":979,"children":983},{"className":980,"code":981,"language":982,"meta":16,"style":16},"language-typescript shiki shiki-themes github-dark","\u002F\u002F middleware.ts\nimport { NextRequest, NextResponse } from 'next\u002Fserver';\n\nexport async function middleware(req: NextRequest) {\n  const userId = req.cookies.get('userId')?.value;\n  \n  if (!userId) {\n    return NextResponse.redirect(new URL('\u002Flogin', req.url));\n  }\n\n  \u002F\u002F Vercel KV (compatibile con Redis, infrastruttura Upstash)\n  const userCtx = await fetch(`https:\u002F\u002FYOUR_KV_ENDPOINT\u002Fget\u002Fuser:${userId}`);\n  const data = await userCtx.json();\n\n  \u002F\u002F Aggiungi contesto agli header della request, passa al prossimo handler\n  const response = NextResponse.next();\n  response.headers.set('X-User-Context', JSON.stringify(data));\n  \n  return response;\n}\n\nexport const config = {\n  matcher: ['\u002Fdashboard\u002F:path*', '\u002Fcheckout\u002F:path*'],\n};\n","typescript",[984],{"type":32,"tag":80,"props":985,"children":986},{"__ignoreMap":16},[987,995,1022,1029,1074,1113,1121,1142,1186,1194,1201,1209,1254,1289,1296,1304,1333,1378,1385,1397,1404,1411,1436,1463],{"type":32,"tag":84,"props":988,"children":989},{"class":86,"line":87},[990],{"type":32,"tag":84,"props":991,"children":992},{"style":91},[993],{"type":37,"value":994},"\u002F\u002F middleware.ts\n",{"type":32,"tag":84,"props":996,"children":997},{"class":86,"line":97},[998,1003,1008,1013,1018],{"type":32,"tag":84,"props":999,"children":1000},{"style":101},[1001],{"type":37,"value":1002},"import",{"type":32,"tag":84,"props":1004,"children":1005},{"style":112},[1006],{"type":37,"value":1007}," { NextRequest, NextResponse } ",{"type":32,"tag":84,"props":1009,"children":1010},{"style":101},[1011],{"type":37,"value":1012},"from",{"type":32,"tag":84,"props":1014,"children":1015},{"style":291},[1016],{"type":37,"value":1017}," 'next\u002Fserver'",{"type":32,"tag":84,"props":1019,"children":1020},{"style":112},[1021],{"type":37,"value":911},{"type":32,"tag":84,"props":1023,"children":1024},{"class":86,"line":118},[1025],{"type":32,"tag":84,"props":1026,"children":1027},{"emptyLinePlaceholder":230},[1028],{"type":37,"value":233},{"type":32,"tag":84,"props":1030,"children":1031},{"class":86,"line":159},[1032,1036,1041,1046,1051,1055,1060,1065,1070],{"type":32,"tag":84,"props":1033,"children":1034},{"style":101},[1035],{"type":37,"value":104},{"type":32,"tag":84,"props":1037,"children":1038},{"style":101},[1039],{"type":37,"value":1040}," async",{"type":32,"tag":84,"props":1042,"children":1043},{"style":101},[1044],{"type":37,"value":1045}," function",{"type":32,"tag":84,"props":1047,"children":1048},{"style":127},[1049],{"type":37,"value":1050}," middleware",{"type":32,"tag":84,"props":1052,"children":1053},{"style":112},[1054],{"type":37,"value":135},{"type":32,"tag":84,"props":1056,"children":1057},{"style":138},[1058],{"type":37,"value":1059},"req",{"type":32,"tag":84,"props":1061,"children":1062},{"style":101},[1063],{"type":37,"value":1064},":",{"type":32,"tag":84,"props":1066,"children":1067},{"style":127},[1068],{"type":37,"value":1069}," NextRequest",{"type":32,"tag":84,"props":1071,"children":1072},{"style":112},[1073],{"type":37,"value":156},{"type":32,"tag":84,"props":1075,"children":1076},{"class":86,"line":194},[1077,1082,1086,1090,1095,1099,1103,1108],{"type":32,"tag":84,"props":1078,"children":1079},{"style":101},[1080],{"type":37,"value":1081},"  const",{"type":32,"tag":84,"props":1083,"children":1084},{"style":168},[1085],{"type":37,"value":204},{"type":32,"tag":84,"props":1087,"children":1088},{"style":101},[1089],{"type":37,"value":176},{"type":32,"tag":84,"props":1091,"children":1092},{"style":112},[1093],{"type":37,"value":1094}," req.cookies.",{"type":32,"tag":84,"props":1096,"children":1097},{"style":127},[1098],{"type":37,"value":284},{"type":32,"tag":84,"props":1100,"children":1101},{"style":112},[1102],{"type":37,"value":135},{"type":32,"tag":84,"props":1104,"children":1105},{"style":291},[1106],{"type":37,"value":1107},"'userId'",{"type":32,"tag":84,"props":1109,"children":1110},{"style":112},[1111],{"type":37,"value":1112},")?.value;\n",{"type":32,"tag":84,"props":1114,"children":1115},{"class":86,"line":226},[1116],{"type":32,"tag":84,"props":1117,"children":1118},{"style":112},[1119],{"type":37,"value":1120},"  \n",{"type":32,"tag":84,"props":1122,"children":1123},{"class":86,"line":236},[1124,1129,1133,1137],{"type":32,"tag":84,"props":1125,"children":1126},{"style":101},[1127],{"type":37,"value":1128},"  if",{"type":32,"tag":84,"props":1130,"children":1131},{"style":112},[1132],{"type":37,"value":341},{"type":32,"tag":84,"props":1134,"children":1135},{"style":101},[1136],{"type":37,"value":346},{"type":32,"tag":84,"props":1138,"children":1139},{"style":112},[1140],{"type":37,"value":1141},"userId) {\n",{"type":32,"tag":84,"props":1143,"children":1144},{"class":86,"line":245},[1145,1149,1154,1159,1163,1168,1172,1176,1181],{"type":32,"tag":84,"props":1146,"children":1147},{"style":101},[1148],{"type":37,"value":498},{"type":32,"tag":84,"props":1150,"children":1151},{"style":112},[1152],{"type":37,"value":1153}," NextResponse.",{"type":32,"tag":84,"props":1155,"children":1156},{"style":127},[1157],{"type":37,"value":1158},"redirect",{"type":32,"tag":84,"props":1160,"children":1161},{"style":112},[1162],{"type":37,"value":135},{"type":32,"tag":84,"props":1164,"children":1165},{"style":101},[1166],{"type":37,"value":1167},"new",{"type":32,"tag":84,"props":1169,"children":1170},{"style":127},[1171],{"type":37,"value":186},{"type":32,"tag":84,"props":1173,"children":1174},{"style":112},[1175],{"type":37,"value":135},{"type":32,"tag":84,"props":1177,"children":1178},{"style":291},[1179],{"type":37,"value":1180},"'\u002Flogin'",{"type":32,"tag":84,"props":1182,"children":1183},{"style":112},[1184],{"type":37,"value":1185},", req.url));\n",{"type":32,"tag":84,"props":1187,"children":1188},{"class":86,"line":26},[1189],{"type":32,"tag":84,"props":1190,"children":1191},{"style":112},[1192],{"type":37,"value":1193},"  }\n",{"type":32,"tag":84,"props":1195,"children":1196},{"class":86,"line":330},[1197],{"type":32,"tag":84,"props":1198,"children":1199},{"emptyLinePlaceholder":230},[1200],{"type":37,"value":233},{"type":32,"tag":84,"props":1202,"children":1203},{"class":86,"line":354},[1204],{"type":32,"tag":84,"props":1205,"children":1206},{"style":91},[1207],{"type":37,"value":1208},"  \u002F\u002F Vercel KV (compatibile con Redis, infrastruttura Upstash)\n",{"type":32,"tag":84,"props":1210,"children":1211},{"class":86,"line":395},[1212,1216,1220,1224,1228,1232,1236,1241,1245,1249],{"type":32,"tag":84,"props":1213,"children":1214},{"style":101},[1215],{"type":37,"value":1081},{"type":32,"tag":84,"props":1217,"children":1218},{"style":168},[1219],{"type":37,"value":255},{"type":32,"tag":84,"props":1221,"children":1222},{"style":101},[1223],{"type":37,"value":176},{"type":32,"tag":84,"props":1225,"children":1226},{"style":101},[1227],{"type":37,"value":264},{"type":32,"tag":84,"props":1229,"children":1230},{"style":127},[1231],{"type":37,"value":130},{"type":32,"tag":84,"props":1233,"children":1234},{"style":112},[1235],{"type":37,"value":135},{"type":32,"tag":84,"props":1237,"children":1238},{"style":291},[1239],{"type":37,"value":1240},"`https:\u002F\u002FYOUR_KV_ENDPOINT\u002Fget\u002Fuser:${",{"type":32,"tag":84,"props":1242,"children":1243},{"style":112},[1244],{"type":37,"value":299},{"type":32,"tag":84,"props":1246,"children":1247},{"style":291},[1248],{"type":37,"value":304},{"type":32,"tag":84,"props":1250,"children":1251},{"style":112},[1252],{"type":37,"value":1253},");\n",{"type":32,"tag":84,"props":1255,"children":1256},{"class":86,"line":404},[1257,1261,1266,1270,1274,1279,1284],{"type":32,"tag":84,"props":1258,"children":1259},{"style":101},[1260],{"type":37,"value":1081},{"type":32,"tag":84,"props":1262,"children":1263},{"style":168},[1264],{"type":37,"value":1265}," data",{"type":32,"tag":84,"props":1267,"children":1268},{"style":101},[1269],{"type":37,"value":176},{"type":32,"tag":84,"props":1271,"children":1272},{"style":101},[1273],{"type":37,"value":264},{"type":32,"tag":84,"props":1275,"children":1276},{"style":112},[1277],{"type":37,"value":1278}," userCtx.",{"type":32,"tag":84,"props":1280,"children":1281},{"style":127},[1282],{"type":37,"value":1283},"json",{"type":32,"tag":84,"props":1285,"children":1286},{"style":112},[1287],{"type":37,"value":1288},"();\n",{"type":32,"tag":84,"props":1290,"children":1291},{"class":86,"line":412},[1292],{"type":32,"tag":84,"props":1293,"children":1294},{"emptyLinePlaceholder":230},[1295],{"type":37,"value":233},{"type":32,"tag":84,"props":1297,"children":1298},{"class":86,"line":421},[1299],{"type":32,"tag":84,"props":1300,"children":1301},{"style":91},[1302],{"type":37,"value":1303},"  \u002F\u002F Aggiungi contesto agli header della request, passa al prossimo handler\n",{"type":32,"tag":84,"props":1305,"children":1306},{"class":86,"line":448},[1307,1311,1316,1320,1324,1329],{"type":32,"tag":84,"props":1308,"children":1309},{"style":101},[1310],{"type":37,"value":1081},{"type":32,"tag":84,"props":1312,"children":1313},{"style":168},[1314],{"type":37,"value":1315}," response",{"type":32,"tag":84,"props":1317,"children":1318},{"style":101},[1319],{"type":37,"value":176},{"type":32,"tag":84,"props":1321,"children":1322},{"style":112},[1323],{"type":37,"value":1153},{"type":32,"tag":84,"props":1325,"children":1326},{"style":127},[1327],{"type":37,"value":1328},"next",{"type":32,"tag":84,"props":1330,"children":1331},{"style":112},[1332],{"type":37,"value":1288},{"type":32,"tag":84,"props":1334,"children":1335},{"class":86,"line":457},[1336,1341,1346,1350,1355,1359,1364,1368,1373],{"type":32,"tag":84,"props":1337,"children":1338},{"style":112},[1339],{"type":37,"value":1340},"  response.headers.",{"type":32,"tag":84,"props":1342,"children":1343},{"style":127},[1344],{"type":37,"value":1345},"set",{"type":32,"tag":84,"props":1347,"children":1348},{"style":112},[1349],{"type":37,"value":135},{"type":32,"tag":84,"props":1351,"children":1352},{"style":291},[1353],{"type":37,"value":1354},"'X-User-Context'",{"type":32,"tag":84,"props":1356,"children":1357},{"style":112},[1358],{"type":37,"value":146},{"type":32,"tag":84,"props":1360,"children":1361},{"style":168},[1362],{"type":37,"value":1363},"JSON",{"type":32,"tag":84,"props":1365,"children":1366},{"style":112},[1367],{"type":37,"value":279},{"type":32,"tag":84,"props":1369,"children":1370},{"style":127},[1371],{"type":37,"value":1372},"stringify",{"type":32,"tag":84,"props":1374,"children":1375},{"style":112},[1376],{"type":37,"value":1377},"(data));\n",{"type":32,"tag":84,"props":1379,"children":1380},{"class":86,"line":466},[1381],{"type":32,"tag":84,"props":1382,"children":1383},{"style":112},[1384],{"type":37,"value":1120},{"type":32,"tag":84,"props":1386,"children":1387},{"class":86,"line":475},[1388,1392],{"type":32,"tag":84,"props":1389,"children":1390},{"style":101},[1391],{"type":37,"value":653},{"type":32,"tag":84,"props":1393,"children":1394},{"style":112},[1395],{"type":37,"value":1396}," response;\n",{"type":32,"tag":84,"props":1398,"children":1399},{"class":86,"line":484},[1400],{"type":32,"tag":84,"props":1401,"children":1402},{"style":112},[1403],{"type":37,"value":870},{"type":32,"tag":84,"props":1405,"children":1406},{"class":86,"line":492},[1407],{"type":32,"tag":84,"props":1408,"children":1409},{"emptyLinePlaceholder":230},[1410],{"type":37,"value":233},{"type":32,"tag":84,"props":1412,"children":1413},{"class":86,"line":514},[1414,1418,1423,1428,1432],{"type":32,"tag":84,"props":1415,"children":1416},{"style":101},[1417],{"type":37,"value":104},{"type":32,"tag":84,"props":1419,"children":1420},{"style":101},[1421],{"type":37,"value":1422}," const",{"type":32,"tag":84,"props":1424,"children":1425},{"style":168},[1426],{"type":37,"value":1427}," config",{"type":32,"tag":84,"props":1429,"children":1430},{"style":101},[1431],{"type":37,"value":176},{"type":32,"tag":84,"props":1433,"children":1434},{"style":112},[1435],{"type":37,"value":115},{"type":32,"tag":84,"props":1437,"children":1438},{"class":86,"line":523},[1439,1444,1449,1453,1458],{"type":32,"tag":84,"props":1440,"children":1441},{"style":112},[1442],{"type":37,"value":1443},"  matcher: [",{"type":32,"tag":84,"props":1445,"children":1446},{"style":291},[1447],{"type":37,"value":1448},"'\u002Fdashboard\u002F:path*'",{"type":32,"tag":84,"props":1450,"children":1451},{"style":112},[1452],{"type":37,"value":146},{"type":32,"tag":84,"props":1454,"children":1455},{"style":291},[1456],{"type":37,"value":1457},"'\u002Fcheckout\u002F:path*'",{"type":32,"tag":84,"props":1459,"children":1460},{"style":112},[1461],{"type":37,"value":1462},"],\n",{"type":32,"tag":84,"props":1464,"children":1465},{"class":86,"line":547},[1466],{"type":32,"tag":84,"props":1467,"children":1468},{"style":112},[1469],{"type":37,"value":601},{"type":32,"tag":33,"props":1471,"children":1472},{},[1473],{"type":37,"value":1474},"Su Vercel Edge il cold start è 3-8ms, leggermente più lento di Cloudflare, ma l'integrazione di Next.js con ISR (Incremental Static Regeneration) è robusta. Puoi generare una pagina staticamente e arricchirla con il contesto utente in edge — logica di \"streaming SSR\". Esempio: il layout principale è HTML statico, il widget utente viene iniettato in edge.",{"type":32,"tag":40,"props":1476,"children":1478},{"id":1477},"trade-off-dimensione-bundle-debug-costo",[1479],{"type":37,"value":1480},"Trade-off: Dimensione Bundle, Debug, Costo",{"type":32,"tag":33,"props":1482,"children":1483},{},[1484,1486,1492,1493,1499,1501,1507,1509,1515,1517,1523],{"type":37,"value":1485},"Il runtime edge ha limitazioni — non dispone dell'intera API di Node.js. Su Cloudflare Workers i moduli Node nativi non girano (ad es. ",{"type":32,"tag":80,"props":1487,"children":1489},{"className":1488},[],[1490],{"type":37,"value":1491},"fs",{"type":37,"value":146},{"type":32,"tag":80,"props":1494,"children":1496},{"className":1495},[],[1497],{"type":37,"value":1498},"child_process",{"type":37,"value":1500},"), lo stesso vale per Vercel Edge. Devi ridurre al minimo le dipendenze. Esempio: sostituisci ",{"type":32,"tag":80,"props":1502,"children":1504},{"className":1503},[],[1505],{"type":37,"value":1506},"date-fns",{"type":37,"value":1508}," con ",{"type":32,"tag":80,"props":1510,"children":1512},{"className":1511},[],[1513],{"type":37,"value":1514},"dayjs",{"type":37,"value":1516}," (2KB vs 70KB), ",{"type":32,"tag":80,"props":1518,"children":1520},{"className":1519},[],[1521],{"type":37,"value":1522},"lodash",{"type":37,"value":1524}," con i metodi ES6 nativi.",{"type":32,"tag":33,"props":1526,"children":1527},{},[1528],{"type":32,"tag":924,"props":1529,"children":1530},{},[1531],{"type":37,"value":1532},"Limiti di dimensione bundle:",{"type":32,"tag":930,"props":1534,"children":1535},{},[1536,1541],{"type":32,"tag":934,"props":1537,"children":1538},{},[1539],{"type":37,"value":1540},"Cloudflare Workers: 1MB (compresso 5MB)",{"type":32,"tag":934,"props":1542,"children":1543},{},[1544],{"type":37,"value":1545},"Vercel Edge: 1MB (middleware)",{"type":32,"tag":33,"props":1547,"children":1548},{},[1549,1551,1557],{"type":37,"value":1550},"In produzione non devi superare 200KB — ogni KB aggiunge 0.5-1ms di latenza (parsing + esecuzione). Tree-shaking e code splitting sono critici. Se usi React, ",{"type":32,"tag":80,"props":1552,"children":1554},{"className":1553},[],[1555],{"type":37,"value":1556},"preact",{"type":37,"value":1558}," (3KB) è più conveniente.",{"type":32,"tag":33,"props":1560,"children":1561},{},[1562,1567,1569,1575,1577,1583,1585,1591],{"type":32,"tag":924,"props":1563,"children":1564},{},[1565],{"type":37,"value":1566},"Debug:",{"type":37,"value":1568}," In edge trovi ",{"type":32,"tag":80,"props":1570,"children":1572},{"className":1571},[],[1573],{"type":37,"value":1574},"console.log",{"type":37,"value":1576}," ma mancano i traceback completi. Con Cloudflare Wrangler CLI puoi configurare un ambiente di test locale (",{"type":32,"tag":80,"props":1578,"children":1580},{"className":1579},[],[1581],{"type":37,"value":1582},"wrangler dev",{"type":37,"value":1584},"), su Vercel il comando ",{"type":32,"tag":80,"props":1586,"children":1588},{"className":1587},[],[1589],{"type":37,"value":1590},"vercel dev",{"type":37,"value":1592}," simula il runtime edge. In produzione un servizio di error tracking come Sentry è indispensabile — invia i log degli errori tramite HTTP POST dall'isolate edge.",{"type":32,"tag":33,"props":1594,"children":1595},{},[1596,1601],{"type":32,"tag":924,"props":1597,"children":1598},{},[1599],{"type":37,"value":1600},"Costo:",{"type":37,"value":1602}," Cloudflare Workers offre i primi 100K request\u002Fgiorno gratuitamente, poi $0.50 per milione. Lo storage KV è gratuito per il primo 1GB, le letture costano $0.50 per 10 milioni. Con Vercel Edge le funzioni sono incluse nel piano — il piano Pro include 1 milione di esecuzioni. Per un sito con 10 milioni di request\u002Fmese, il costo mensile edge è $20-40, mentre la stessa configurazione origin-based costa $150-200 in risorse server. Man mano che il traffico cresce, il vantaggio economico dell'edge aumenta.",{"type":32,"tag":40,"props":1604,"children":1606},{"id":1605},"strategia-kv-store-write-through-vs-write-behind",[1607],{"type":37,"value":1608},"Strategia KV Store: Write-Through vs Write-Behind",{"type":32,"tag":33,"props":1610,"children":1611},{},[1612],{"type":37,"value":1613},"Come scrivi i dati nel KV impatta direttamente sulla latenza. Due pattern principali:",{"type":32,"tag":33,"props":1615,"children":1616},{},[1617,1622],{"type":32,"tag":924,"props":1618,"children":1619},{},[1620],{"type":37,"value":1621},"Write-Through (Sincrono):",{"type":37,"value":1623},"\nQuando l'API di origine riceve una mutazione, scrivi contemporaneamente sul database e nel KV, attendi che entrambi siano completati, poi rispondi. Garantisci coerenza, ma la latenza di scrittura è 150-250ms (due hop di rete).",{"type":32,"tag":73,"props":1625,"children":1627},{"className":75,"code":1626,"language":77,"meta":16,"style":16},"\u002F\u002F Handler API origine\napp.post('\u002Fcart\u002Fadd', async (req, res) => {\n  const { userId, productId } = req.body;\n  \n  \u002F\u002F 1. Scrivi su Postgres\n  await db.query('INSERT INTO cart_items ...');\n  \n  \u002F\u002F 2. Aggiorna KV\n  const userCtx = await getUserContext(userId);\n  userCtx.cart.push(productId);\n  await kv.put(`user:${userId}`, JSON.stringify(userCtx));\n  \n  res.json({ success: true });\n});\n",[1628],{"type":32,"tag":80,"props":1629,"children":1630},{"__ignoreMap":16},[1631,1639,1701,1741,1748,1756,1787,1794,1802,1831,1849,1903,1910,1936],{"type":32,"tag":84,"props":1632,"children":1633},{"class":86,"line":87},[1634],{"type":32,"tag":84,"props":1635,"children":1636},{"style":91},[1637],{"type":37,"value":1638},"\u002F\u002F Handler API origine\n",{"type":32,"tag":84,"props":1640,"children":1641},{"class":86,"line":97},[1642,1647,1652,1656,1661,1665,1670,1674,1678,1682,1687,1692,1697],{"type":32,"tag":84,"props":1643,"children":1644},{"style":112},[1645],{"type":37,"value":1646},"app.",{"type":32,"tag":84,"props":1648,"children":1649},{"style":127},[1650],{"type":37,"value":1651},"post",{"type":32,"tag":84,"props":1653,"children":1654},{"style":112},[1655],{"type":37,"value":135},{"type":32,"tag":84,"props":1657,"children":1658},{"style":291},[1659],{"type":37,"value":1660},"'\u002Fcart\u002Fadd'",{"type":32,"tag":84,"props":1662,"children":1663},{"style":112},[1664],{"type":37,"value":146},{"type":32,"tag":84,"props":1666,"children":1667},{"style":101},[1668],{"type":37,"value":1669},"async",{"type":32,"tag":84,"props":1671,"children":1672},{"style":112},[1673],{"type":37,"value":341},{"type":32,"tag":84,"props":1675,"children":1676},{"style":138},[1677],{"type":37,"value":1059},{"type":32,"tag":84,"props":1679,"children":1680},{"style":112},[1681],{"type":37,"value":146},{"type":32,"tag":84,"props":1683,"children":1684},{"style":138},[1685],{"type":37,"value":1686},"res",{"type":32,"tag":84,"props":1688,"children":1689},{"style":112},[1690],{"type":37,"value":1691},") ",{"type":32,"tag":84,"props":1693,"children":1694},{"style":101},[1695],{"type":37,"value":1696},"=>",{"type":32,"tag":84,"props":1698,"children":1699},{"style":112},[1700],{"type":37,"value":115},{"type":32,"tag":84,"props":1702,"children":1703},{"class":86,"line":118},[1704,1708,1713,1717,1721,1726,1731,1736],{"type":32,"tag":84,"props":1705,"children":1706},{"style":101},[1707],{"type":37,"value":1081},{"type":32,"tag":84,"props":1709,"children":1710},{"style":112},[1711],{"type":37,"value":1712}," { ",{"type":32,"tag":84,"props":1714,"children":1715},{"style":168},[1716],{"type":37,"value":299},{"type":32,"tag":84,"props":1718,"children":1719},{"style":112},[1720],{"type":37,"value":146},{"type":32,"tag":84,"props":1722,"children":1723},{"style":168},[1724],{"type":37,"value":1725},"productId",{"type":32,"tag":84,"props":1727,"children":1728},{"style":112},[1729],{"type":37,"value":1730}," } ",{"type":32,"tag":84,"props":1732,"children":1733},{"style":101},[1734],{"type":37,"value":1735},"=",{"type":32,"tag":84,"props":1737,"children":1738},{"style":112},[1739],{"type":37,"value":1740}," req.body;\n",{"type":32,"tag":84,"props":1742,"children":1743},{"class":86,"line":159},[1744],{"type":32,"tag":84,"props":1745,"children":1746},{"style":112},[1747],{"type":37,"value":1120},{"type":32,"tag":84,"props":1749,"children":1750},{"class":86,"line":194},[1751],{"type":32,"tag":84,"props":1752,"children":1753},{"style":91},[1754],{"type":37,"value":1755},"  \u002F\u002F 1. Scrivi su Postgres\n",{"type":32,"tag":84,"props":1757,"children":1758},{"class":86,"line":226},[1759,1764,1769,1774,1778,1783],{"type":32,"tag":84,"props":1760,"children":1761},{"style":101},[1762],{"type":37,"value":1763},"  await",{"type":32,"tag":84,"props":1765,"children":1766},{"style":112},[1767],{"type":37,"value":1768}," db.",{"type":32,"tag":84,"props":1770,"children":1771},{"style":127},[1772],{"type":37,"value":1773},"query",{"type":32,"tag":84,"props":1775,"children":1776},{"style":112},[1777],{"type":37,"value":135},{"type":32,"tag":84,"props":1779,"children":1780},{"style":291},[1781],{"type":37,"value":1782},"'INSERT INTO cart_items ...'",{"type":32,"tag":84,"props":1784,"children":1785},{"style":112},[1786],{"type":37,"value":1253},{"type":32,"tag":84,"props":1788,"children":1789},{"class":86,"line":236},[1790],{"type":32,"tag":84,"props":1791,"children":1792},{"style":112},[1793],{"type":37,"value":1120},{"type":32,"tag":84,"props":1795,"children":1796},{"class":86,"line":245},[1797],{"type":32,"tag":84,"props":1798,"children":1799},{"style":91},[1800],{"type":37,"value":1801},"  \u002F\u002F 2. Aggiorna KV\n",{"type":32,"tag":84,"props":1803,"children":1804},{"class":86,"line":26},[1805,1809,1813,1817,1821,1826],{"type":32,"tag":84,"props":1806,"children":1807},{"style":101},[1808],{"type":37,"value":1081},{"type":32,"tag":84,"props":1810,"children":1811},{"style":168},[1812],{"type":37,"value":255},{"type":32,"tag":84,"props":1814,"children":1815},{"style":101},[1816],{"type":37,"value":176},{"type":32,"tag":84,"props":1818,"children":1819},{"style":101},[1820],{"type":37,"value":264},{"type":32,"tag":84,"props":1822,"children":1823},{"style":127},[1824],{"type":37,"value":1825}," getUserContext",{"type":32,"tag":84,"props":1827,"children":1828},{"style":112},[1829],{"type":37,"value":1830},"(userId);\n",{"type":32,"tag":84,"props":1832,"children":1833},{"class":86,"line":330},[1834,1839,1844],{"type":32,"tag":84,"props":1835,"children":1836},{"style":112},[1837],{"type":37,"value":1838},"  userCtx.cart.",{"type":32,"tag":84,"props":1840,"children":1841},{"style":127},[1842],{"type":37,"value":1843},"push",{"type":32,"tag":84,"props":1845,"children":1846},{"style":112},[1847],{"type":37,"value":1848},"(productId);\n",{"type":32,"tag":84,"props":1850,"children":1851},{"class":86,"line":354},[1852,1856,1861,1866,1870,1874,1878,1882,1886,1890,1894,1898],{"type":32,"tag":84,"props":1853,"children":1854},{"style":101},[1855],{"type":37,"value":1763},{"type":32,"tag":84,"props":1857,"children":1858},{"style":112},[1859],{"type":37,"value":1860}," kv.",{"type":32,"tag":84,"props":1862,"children":1863},{"style":127},[1864],{"type":37,"value":1865},"put",{"type":32,"tag":84,"props":1867,"children":1868},{"style":112},[1869],{"type":37,"value":135},{"type":32,"tag":84,"props":1871,"children":1872},{"style":291},[1873],{"type":37,"value":294},{"type":32,"tag":84,"props":1875,"children":1876},{"style":112},[1877],{"type":37,"value":299},{"type":32,"tag":84,"props":1879,"children":1880},{"style":291},[1881],{"type":37,"value":304},{"type":32,"tag":84,"props":1883,"children":1884},{"style":112},[1885],{"type":37,"value":146},{"type":32,"tag":84,"props":1887,"children":1888},{"style":168},[1889],{"type":37,"value":1363},{"type":32,"tag":84,"props":1891,"children":1892},{"style":112},[1893],{"type":37,"value":279},{"type":32,"tag":84,"props":1895,"children":1896},{"style":127},[1897],{"type":37,"value":1372},{"type":32,"tag":84,"props":1899,"children":1900},{"style":112},[1901],{"type":37,"value":1902},"(userCtx));\n",{"type":32,"tag":84,"props":1904,"children":1905},{"class":86,"line":395},[1906],{"type":32,"tag":84,"props":1907,"children":1908},{"style":112},[1909],{"type":37,"value":1120},{"type":32,"tag":84,"props":1911,"children":1912},{"class":86,"line":404},[1913,1918,1922,1927,1932],{"type":32,"tag":84,"props":1914,"children":1915},{"style":112},[1916],{"type":37,"value":1917},"  res.",{"type":32,"tag":84,"props":1919,"children":1920},{"style":127},[1921],{"type":37,"value":1283},{"type":32,"tag":84,"props":1923,"children":1924},{"style":112},[1925],{"type":37,"value":1926},"({ success: ",{"type":32,"tag":84,"props":1928,"children":1929},{"style":168},[1930],{"type":37,"value":1931},"true",{"type":32,"tag":84,"props":1933,"children":1934},{"style":112},[1935],{"type":37,"value":319},{"type":32,"tag":84,"props":1937,"children":1938},{"class":86,"line":412},[1939],{"type":32,"tag":84,"props":1940,"children":1941},{"style":112},[1942],{"type":37,"value":1943},"});\n",{"type":32,"tag":33,"props":1945,"children":1946},{},[1947,1952],{"type":32,"tag":924,"props":1948,"children":1949},{},[1950],{"type":37,"value":1951},"Write-Behind (Asincrono):",{"type":37,"value":1953},"\nScrivi nel database, rispondi subito, un job in background aggiorna il KV. La latenza di scrittura scende a 50-80ms, ma il KV rischia staleness di 100-200ms.",{"type":32,"tag":73,"props":1955,"children":1957},{"className":75,"code":1956,"language":77,"meta":16,"style":16},"app.post('\u002Fcart\u002Fadd', async (req, res) => {\n  const { userId, productId } = req.body;\n  \n  await db.query('INSERT INTO cart_items ...');\n  \n  \u002F\u002F Metti l'aggiornamento del KV in una coda asincrona\n  queueKVUpdate('user', userId);\n  \n  res.json({ success: true });\n});\n\nasync function queueKVUpdate(type, id) {\n  \u002F\u002F Coda Redis o Cloudflare Durable Objects\n  await redis.lpush('kv_updates', JSON.stringify({ type, id }));\n}\n",[1958],{"type":32,"tag":80,"props":1959,"children":1960},{"__ignoreMap":16},[1961,2016,2051,2058,2085,2092,2100,2122,2129,2152,2159,2166,2204,2212,2259],{"type":32,"tag":84,"props":1962,"children":1963},{"class":86,"line":87},[1964,1968,1972,1976,1980,1984,1988,1992,1996,2000,2004,2008,2012],{"type":32,"tag":84,"props":1965,"children":1966},{"style":112},[1967],{"type":37,"value":1646},{"type":32,"tag":84,"props":1969,"children":1970},{"style":127},[1971],{"type":37,"value":1651},{"type":32,"tag":84,"props":1973,"children":1974},{"style":112},[1975],{"type":37,"value":135},{"type":32,"tag":84,"props":1977,"children":1978},{"style":291},[1979],{"type":37,"value":1660},{"type":32,"tag":84,"props":1981,"children":1982},{"style":112},[1983],{"type":37,"value":146},{"type":32,"tag":84,"props":1985,"children":1986},{"style":101},[1987],{"type":37,"value":1669},{"type":32,"tag":84,"props":1989,"children":1990},{"style":112},[1991],{"type":37,"value":341},{"type":32,"tag":84,"props":1993,"children":1994},{"style":138},[1995],{"type":37,"value":1059},{"type":32,"tag":84,"props":1997,"children":1998},{"style":112},[1999],{"type":37,"value":146},{"type":32,"tag":84,"props":2001,"children":2002},{"style":138},[2003],{"type":37,"value":1686},{"type":32,"tag":84,"props":2005,"children":2006},{"style":112},[2007],{"type":37,"value":1691},{"type":32,"tag":84,"props":2009,"children":2010},{"style":101},[2011],{"type":37,"value":1696},{"type":32,"tag":84,"props":2013,"children":2014},{"style":112},[2015],{"type":37,"value":115},{"type":32,"tag":84,"props":2017,"children":2018},{"class":86,"line":97},[2019,2023,2027,2031,2035,2039,2043,2047],{"type":32,"tag":84,"props":2020,"children":2021},{"style":101},[2022],{"type":37,"value":1081},{"type":32,"tag":84,"props":2024,"children":2025},{"style":112},[2026],{"type":37,"value":1712},{"type":32,"tag":84,"props":2028,"children":2029},{"style":168},[2030],{"type":37,"value":299},{"type":32,"tag":84,"props":2032,"children":2033},{"style":112},[2034],{"type":37,"value":146},{"type":32,"tag":84,"props":2036,"children":2037},{"style":168},[2038],{"type":37,"value":1725},{"type":32,"tag":84,"props":2040,"children":2041},{"style":112},[2042],{"type":37,"value":1730},{"type":32,"tag":84,"props":2044,"children":2045},{"style":101},[2046],{"type":37,"value":1735},{"type":32,"tag":84,"props":2048,"children":2049},{"style":112},[2050],{"type":37,"value":1740},{"type":32,"tag":84,"props":2052,"children":2053},{"class":86,"line":118},[2054],{"type":32,"tag":84,"props":2055,"children":2056},{"style":112},[2057],{"type":37,"value":1120},{"type":32,"tag":84,"props":2059,"children":2060},{"class":86,"line":159},[2061,2065,2069,2073,2077,2081],{"type":32,"tag":84,"props":2062,"children":2063},{"style":101},[2064],{"type":37,"value":1763},{"type":32,"tag":84,"props":2066,"children":2067},{"style":112},[2068],{"type":37,"value":1768},{"type":32,"tag":84,"props":2070,"children":2071},{"style":127},[2072],{"type":37,"value":1773},{"type":32,"tag":84,"props":2074,"children":2075},{"style":112},[2076],{"type":37,"value":135},{"type":32,"tag":84,"props":2078,"children":2079},{"style":291},[2080],{"type":37,"value":1782},{"type":32,"tag":84,"props":2082,"children":2083},{"style":112},[2084],{"type":37,"value":1253},{"type":32,"tag":84,"props":2086,"children":2087},{"class":86,"line":194},[2088],{"type":32,"tag":84,"props":2089,"children":2090},{"style":112},[2091],{"type":37,"value":1120},{"type":32,"tag":84,"props":2093,"children":2094},{"class":86,"line":226},[2095],{"type":32,"tag":84,"props":2096,"children":2097},{"style":91},[2098],{"type":37,"value":2099},"  \u002F\u002F Metti l'aggiornamento del KV in una coda asincrona\n",{"type":32,"tag":84,"props":2101,"children":2102},{"class":86,"line":236},[2103,2108,2112,2117],{"type":32,"tag":84,"props":2104,"children":2105},{"style":127},[2106],{"type":37,"value":2107},"  queueKVUpdate",{"type":32,"tag":84,"props":2109,"children":2110},{"style":112},[2111],{"type":37,"value":135},{"type":32,"tag":84,"props":2113,"children":2114},{"style":291},[2115],{"type":37,"value":2116},"'user'",{"type":32,"tag":84,"props":2118,"children":2119},{"style":112},[2120],{"type":37,"value":2121},", userId);\n",{"type":32,"tag":84,"props":2123,"children":2124},{"class":86,"line":245},[2125],{"type":32,"tag":84,"props":2126,"children":2127},{"style":112},[2128],{"type":37,"value":1120},{"type":32,"tag":84,"props":2130,"children":2131},{"class":86,"line":26},[2132,2136,2140,2144,2148],{"type":32,"tag":84,"props":2133,"children":2134},{"style":112},[2135],{"type":37,"value":1917},{"type":32,"tag":84,"props":2137,"children":2138},{"style":127},[2139],{"type":37,"value":1283},{"type":32,"tag":84,"props":2141,"children":2142},{"style":112},[2143],{"type":37,"value":1926},{"type":32,"tag":84,"props":2145,"children":2146},{"style":168},[2147],{"type":37,"value":1931},{"type":32,"tag":84,"props":2149,"children":2150},{"style":112},[2151],{"type":37,"value":319},{"type":32,"tag":84,"props":2153,"children":2154},{"class":86,"line":330},[2155],{"type":32,"tag":84,"props":2156,"children":2157},{"style":112},[2158],{"type":37,"value":1943},{"type":32,"tag":84,"props":2160,"children":2161},{"class":86,"line":354},[2162],{"type":32,"tag":84,"props":2163,"children":2164},{"emptyLinePlaceholder":230},[2165],{"type":37,"value":233},{"type":32,"tag":84,"props":2167,"children":2168},{"class":86,"line":395},[2169,2173,2177,2182,2186,2191,2195,2200],{"type":32,"tag":84,"props":2170,"children":2171},{"style":101},[2172],{"type":37,"value":1669},{"type":32,"tag":84,"props":2174,"children":2175},{"style":101},[2176],{"type":37,"value":1045},{"type":32,"tag":84,"props":2178,"children":2179},{"style":127},[2180],{"type":37,"value":2181}," queueKVUpdate",{"type":32,"tag":84,"props":2183,"children":2184},{"style":112},[2185],{"type":37,"value":135},{"type":32,"tag":84,"props":2187,"children":2188},{"style":138},[2189],{"type":37,"value":2190},"type",{"type":32,"tag":84,"props":2192,"children":2193},{"style":112},[2194],{"type":37,"value":146},{"type":32,"tag":84,"props":2196,"children":2197},{"style":138},[2198],{"type":37,"value":2199},"id",{"type":32,"tag":84,"props":2201,"children":2202},{"style":112},[2203],{"type":37,"value":156},{"type":32,"tag":84,"props":2205,"children":2206},{"class":86,"line":404},[2207],{"type":32,"tag":84,"props":2208,"children":2209},{"style":91},[2210],{"type":37,"value":2211},"  \u002F\u002F Coda Redis o Cloudflare Durable Objects\n",{"type":32,"tag":84,"props":2213,"children":2214},{"class":86,"line":412},[2215,2219,2224,2229,2233,2238,2242,2246,2250,2254],{"type":32,"tag":84,"props":2216,"children":2217},{"style":101},[2218],{"type":37,"value":1763},{"type":32,"tag":84,"props":2220,"children":2221},{"style":112},[2222],{"type":37,"value":2223}," redis.",{"type":32,"tag":84,"props":2225,"children":2226},{"style":127},[2227],{"type":37,"value":2228},"lpush",{"type":32,"tag":84,"props":2230,"children":2231},{"style":112},[2232],{"type":37,"value":135},{"type":32,"tag":84,"props":2234,"children":2235},{"style":291},[2236],{"type":37,"value":2237},"'kv_updates'",{"type":32,"tag":84,"props":2239,"children":2240},{"style":112},[2241],{"type":37,"value":146},{"type":32,"tag":84,"props":2243,"children":2244},{"style":168},[2245],{"type":37,"value":1363},{"type":32,"tag":84,"props":2247,"children":2248},{"style":112},[2249],{"type":37,"value":279},{"type":32,"tag":84,"props":2251,"children":2252},{"style":127},[2253],{"type":37,"value":1372},{"type":32,"tag":84,"props":2255,"children":2256},{"style":112},[2257],{"type":37,"value":2258},"({ type, id }));\n",{"type":32,"tag":84,"props":2260,"children":2261},{"class":86,"line":421},[2262],{"type":32,"tag":84,"props":2263,"children":2264},{"style":112},[2265],{"type":37,"value":870},{"type":32,"tag":33,"props":2267,"children":2268},{},[2269],{"type":37,"value":2270},"In un e-commerce, write-behind ha senso per aggiungere articoli al carrello — l'utente non percepisce un ritardo di 100ms. Per dati critici come i cambiamenti di prezzo, scegli write-through e fai un double-check da origine prima del checkout.",{"type":32,"tag":40,"props":2272,"children":2274},{"id":2273},"layer-di-cache-ibrido-static-edge-ssr",[2275],{"type":37,"value":2276},"Layer di Cache Ibrido: Static + Edge SSR",{"type":32,"tag":33,"props":2278,"children":2279},{},[2280,2282,2291],{"type":37,"value":2281},"Anzichè usare solo edge SSR, un'architettura ibrida static + dynamic è più efficiente. Esempio: nei progetti ",{"type":32,"tag":2283,"props":2284,"children":2288},"a",{"href":2285,"rel":2286},"https:\u002F\u002Fwww.roibase.com.tr\u002Fit\u002Fheadless",[2287],"nofollow",[2289],{"type":37,"value":2290},"Headless Commerce",{"type":37,"value":2292}," di Roibase, il layout della homepage (intestazione, piè di pagina, elenco categorie generali) viene generato staticamente, mentre i blocchi personalizzati per l'utente (icona carrello, nome utente, widget consigli) vengono iniettati in edge. Questo approccio porta il cache hit rate al 92%.",{"type":32,"tag":33,"props":2294,"children":2295},{},[2296],{"type":37,"value":2297},"Con Next.js:",{"type":32,"tag":73,"props":2299,"children":2301},{"className":980,"code":2300,"language":982,"meta":16,"style":16},"\u002F\u002F app\u002Fpage.tsx — Layout statico\nexport default function HomePage() {\n  return (\n    \u003Cmain>\n      \u003CHeader \u002F> {\u002F* Statico *\u002F}\n      \u003CHeroSection \u002F> {\u002F* Statico *\u002F}\n      \u003CUserWidget \u002F> {\u002F* Edge SSR *\u002F}\n      \u003CProductGrid \u002F> {\u002F* ISR statico, revalidate 60s *\u002F}\n    \u003C\u002Fmain>\n  );\n}\n\n\u002F\u002F components\u002FUserWidget.tsx — Server component, runtime edge\nexport const runtime = 'edge';\n\nexport default async function UserWidget() {\n  const userId = cookies().get('userId')?.value;\n  const userCtx = await fetch(`https:\u002F\u002Fkv...\u002Fuser:${userId}`);\n  const data = await userCtx.json();\n\n  return \u003Cdiv>Benvenuto {data.name}\u003C\u002Fdiv>;\n}\n",[2302],{"type":32,"tag":80,"props":2303,"children":2304},{"__ignoreMap":16},[2305,2313,2338,2350,2368,2400,2428,2457,2486,2502,2510,2517,2524,2532,2561,2568,2596,2637,2681,2712,2719,2759],{"type":32,"tag":84,"props":2306,"children":2307},{"class":86,"line":87},[2308],{"type":32,"tag":84,"props":2309,"children":2310},{"style":91},[2311],{"type":37,"value":2312},"\u002F\u002F app\u002Fpage.tsx — Layout statico\n",{"type":32,"tag":84,"props":2314,"children":2315},{"class":86,"line":97},[2316,2320,2324,2328,2333],{"type":32,"tag":84,"props":2317,"children":2318},{"style":101},[2319],{"type":37,"value":104},{"type":32,"tag":84,"props":2321,"children":2322},{"style":101},[2323],{"type":37,"value":109},{"type":32,"tag":84,"props":2325,"children":2326},{"style":101},[2327],{"type":37,"value":1045},{"type":32,"tag":84,"props":2329,"children":2330},{"style":127},[2331],{"type":37,"value":2332}," HomePage",{"type":32,"tag":84,"props":2334,"children":2335},{"style":112},[2336],{"type":37,"value":2337},"() {\n",{"type":32,"tag":84,"props":2339,"children":2340},{"class":86,"line":118},[2341,2345],{"type":32,"tag":84,"props":2342,"children":2343},{"style":101},[2344],{"type":37,"value":653},{"type":32,"tag":84,"props":2346,"children":2347},{"style":112},[2348],{"type":37,"value":2349}," (\n",{"type":32,"tag":84,"props":2351,"children":2352},{"class":86,"line":159},[2353,2358,2363],{"type":32,"tag":84,"props":2354,"children":2355},{"style":112},[2356],{"type":37,"value":2357},"    \u003C",{"type":32,"tag":84,"props":2359,"children":2360},{"style":127},[2361],{"type":37,"value":2362},"main",{"type":32,"tag":84,"props":2364,"children":2365},{"style":112},[2366],{"type":37,"value":2367},">\n",{"type":32,"tag":84,"props":2369,"children":2370},{"class":86,"line":194},[2371,2376,2381,2386,2391,2396],{"type":32,"tag":84,"props":2372,"children":2373},{"style":101},[2374],{"type":37,"value":2375},"      \u003C",{"type":32,"tag":84,"props":2377,"children":2378},{"style":112},[2379],{"type":37,"value":2380},"Header ",{"type":32,"tag":84,"props":2382,"children":2383},{"style":101},[2384],{"type":37,"value":2385},"\u002F>",{"type":32,"tag":84,"props":2387,"children":2388},{"style":112},[2389],{"type":37,"value":2390}," {",{"type":32,"tag":84,"props":2392,"children":2393},{"style":91},[2394],{"type":37,"value":2395},"\u002F* Statico *\u002F",{"type":32,"tag":84,"props":2397,"children":2398},{"style":112},[2399],{"type":37,"value":870},{"type":32,"tag":84,"props":2401,"children":2402},{"class":86,"line":226},[2403,2407,2412,2416,2420,2424],{"type":32,"tag":84,"props":2404,"children":2405},{"style":101},[2406],{"type":37,"value":2375},{"type":32,"tag":84,"props":2408,"children":2409},{"style":112},[2410],{"type":37,"value":2411},"HeroSection ",{"type":32,"tag":84,"props":2413,"children":2414},{"style":101},[2415],{"type":37,"value":2385},{"type":32,"tag":84,"props":2417,"children":2418},{"style":112},[2419],{"type":37,"value":2390},{"type":32,"tag":84,"props":2421,"children":2422},{"style":91},[2423],{"type":37,"value":2395},{"type":32,"tag":84,"props":2425,"children":2426},{"style":112},[2427],{"type":37,"value":870},{"type":32,"tag":84,"props":2429,"children":2430},{"class":86,"line":236},[2431,2435,2440,2444,2448,2453],{"type":32,"tag":84,"props":2432,"children":2433},{"style":101},[2434],{"type":37,"value":2375},{"type":32,"tag":84,"props":2436,"children":2437},{"style":112},[2438],{"type":37,"value":2439},"UserWidget ",{"type":32,"tag":84,"props":2441,"children":2442},{"style":101},[2443],{"type":37,"value":2385},{"type":32,"tag":84,"props":2445,"children":2446},{"style":112},[2447],{"type":37,"value":2390},{"type":32,"tag":84,"props":2449,"children":2450},{"style":91},[2451],{"type":37,"value":2452},"\u002F* Edge SSR *\u002F",{"type":32,"tag":84,"props":2454,"children":2455},{"style":112},[2456],{"type":37,"value":870},{"type":32,"tag":84,"props":2458,"children":2459},{"class":86,"line":245},[2460,2464,2469,2473,2477,2482],{"type":32,"tag":84,"props":2461,"children":2462},{"style":101},[2463],{"type":37,"value":2375},{"type":32,"tag":84,"props":2465,"children":2466},{"style":112},[2467],{"type":37,"value":2468},"ProductGrid ",{"type":32,"tag":84,"props":2470,"children":2471},{"style":101},[2472],{"type":37,"value":2385},{"type":32,"tag":84,"props":2474,"children":2475},{"style":112},[2476],{"type":37,"value":2390},{"type":32,"tag":84,"props":2478,"children":2479},{"style":91},[2480],{"type":37,"value":2481},"\u002F* ISR statico, revalidate 60s *\u002F",{"type":32,"tag":84,"props":2483,"children":2484},{"style":112},[2485],{"type":37,"value":870},{"type":32,"tag":84,"props":2487,"children":2488},{"class":86,"line":26},[2489,2494,2498],{"type":32,"tag":84,"props":2490,"children":2491},{"style":101},[2492],{"type":37,"value":2493},"    \u003C\u002F",{"type":32,"tag":84,"props":2495,"children":2496},{"style":112},[2497],{"type":37,"value":2362},{"type":32,"tag":84,"props":2499,"children":2500},{"style":101},[2501],{"type":37,"value":2367},{"type":32,"tag":84,"props":2503,"children":2504},{"class":86,"line":330},[2505],{"type":32,"tag":84,"props":2506,"children":2507},{"style":112},[2508],{"type":37,"value":2509},"  );\n",{"type":32,"tag":84,"props":2511,"children":2512},{"class":86,"line":354},[2513],{"type":32,"tag":84,"props":2514,"children":2515},{"style":112},[2516],{"type":37,"value":870},{"type":32,"tag":84,"props":2518,"children":2519},{"class":86,"line":395},[2520],{"type":32,"tag":84,"props":2521,"children":2522},{"emptyLinePlaceholder":230},[2523],{"type":37,"value":233},{"type":32,"tag":84,"props":2525,"children":2526},{"class":86,"line":404},[2527],{"type":32,"tag":84,"props":2528,"children":2529},{"style":91},[2530],{"type":37,"value":2531},"\u002F\u002F components\u002FUserWidget.tsx — Server component, runtime edge\n",{"type":32,"tag":84,"props":2533,"children":2534},{"class":86,"line":412},[2535,2539,2543,2548,2552,2557],{"type":32,"tag":84,"props":2536,"children":2537},{"style":101},[2538],{"type":37,"value":104},{"type":32,"tag":84,"props":2540,"children":2541},{"style":101},[2542],{"type":37,"value":1422},{"type":32,"tag":84,"props":2544,"children":2545},{"style":168},[2546],{"type":37,"value":2547}," runtime",{"type":32,"tag":84,"props":2549,"children":2550},{"style":101},[2551],{"type":37,"value":176},{"type":32,"tag":84,"props":2553,"children":2554},{"style":291},[2555],{"type":37,"value":2556}," 'edge'",{"type":32,"tag":84,"props":2558,"children":2559},{"style":112},[2560],{"type":37,"value":911},{"type":32,"tag":84,"props":2562,"children":2563},{"class":86,"line":421},[2564],{"type":32,"tag":84,"props":2565,"children":2566},{"emptyLinePlaceholder":230},[2567],{"type":37,"value":233},{"type":32,"tag":84,"props":2569,"children":2570},{"class":86,"line":448},[2571,2575,2579,2583,2587,2592],{"type":32,"tag":84,"props":2572,"children":2573},{"style":101},[2574],{"type":37,"value":104},{"type":32,"tag":84,"props":2576,"children":2577},{"style":101},[2578],{"type":37,"value":109},{"type":32,"tag":84,"props":2580,"children":2581},{"style":101},[2582],{"type":37,"value":1040},{"type":32,"tag":84,"props":2584,"children":2585},{"style":101},[2586],{"type":37,"value":1045},{"type":32,"tag":84,"props":2588,"children":2589},{"style":127},[2590],{"type":37,"value":2591}," UserWidget",{"type":32,"tag":84,"props":2593,"children":2594},{"style":112},[2595],{"type":37,"value":2337},{"type":32,"tag":84,"props":2597,"children":2598},{"class":86,"line":457},[2599,2603,2607,2611,2616,2621,2625,2629,2633],{"type":32,"tag":84,"props":2600,"children":2601},{"style":101},[2602],{"type":37,"value":1081},{"type":32,"tag":84,"props":2604,"children":2605},{"style":168},[2606],{"type":37,"value":204},{"type":32,"tag":84,"props":2608,"children":2609},{"style":101},[2610],{"type":37,"value":176},{"type":32,"tag":84,"props":2612,"children":2613},{"style":127},[2614],{"type":37,"value":2615}," cookies",{"type":32,"tag":84,"props":2617,"children":2618},{"style":112},[2619],{"type":37,"value":2620},"().",{"type":32,"tag":84,"props":2622,"children":2623},{"style":127},[2624],{"type":37,"value":284},{"type":32,"tag":84,"props":2626,"children":2627},{"style":112},[2628],{"type":37,"value":135},{"type":32,"tag":84,"props":2630,"children":2631},{"style":291},[2632],{"type":37,"value":1107},{"type":32,"tag":84,"props":2634,"children":2635},{"style":112},[2636],{"type":37,"value":1112},{"type":32,"tag":84,"props":2638,"children":2639},{"class":86,"line":466},[2640,2644,2648,2652,2656,2660,2664,2669,2673,2677],{"type":32,"tag":84,"props":2641,"children":2642},{"style":101},[2643],{"type":37,"value":1081},{"type":32,"tag":84,"props":2645,"children":2646},{"style":168},[2647],{"type":37,"value":255},{"type":32,"tag":84,"props":2649,"children":2650},{"style":101},[2651],{"type":37,"value":176},{"type":32,"tag":84,"props":2653,"children":2654},{"style":101},[2655],{"type":37,"value":264},{"type":32,"tag":84,"props":2657,"children":2658},{"style":127},[2659],{"type":37,"value":130},{"type":32,"tag":84,"props":2661,"children":2662},{"style":112},[2663],{"type":37,"value":135},{"type":32,"tag":84,"props":2665,"children":2666},{"style":291},[2667],{"type":37,"value":2668},"`https:\u002F\u002Fkv...\u002Fuser:${",{"type":32,"tag":84,"props":2670,"children":2671},{"style":112},[2672],{"type":37,"value":299},{"type":32,"tag":84,"props":2674,"children":2675},{"style":291},[2676],{"type":37,"value":304},{"type":32,"tag":84,"props":2678,"children":2679},{"style":112},[2680],{"type":37,"value":1253},{"type":32,"tag":84,"props":2682,"children":2683},{"class":86,"line":475},[2684,2688,2692,2696,2700,2704,2708],{"type":32,"tag":84,"props":2685,"children":2686},{"style":101},[2687],{"type":37,"value":1081},{"type":32,"tag":84,"props":2689,"children":2690},{"style":168},[2691],{"type":37,"value":1265},{"type":32,"tag":84,"props":2693,"children":2694},{"style":101},[2695],{"type":37,"value":176},{"type":32,"tag":84,"props":2697,"children":2698},{"style":101},[2699],{"type":37,"value":264},{"type":32,"tag":84,"props":2701,"children":2702},{"style":112},[2703],{"type":37,"value":1278},{"type":32,"tag":84,"props":2705,"children":2706},{"style":127},[2707],{"type":37,"value":1283},{"type":32,"tag":84,"props":2709,"children":2710},{"style":112},[2711],{"type":37,"value":1288},{"type":32,"tag":84,"props":2713,"children":2714},{"class":86,"line":484},[2715],{"type":32,"tag":84,"props":2716,"children":2717},{"emptyLinePlaceholder":230},[2718],{"type":37,"value":233},{"type":32,"tag":84,"props":2720,"children":2721},{"class":86,"line":492},[2722,2726,2731,2736,2741,2746,2750,2755],{"type":32,"tag":84,"props":2723,"children":2724},{"style":101},[2725],{"type":37,"value":653},{"type":32,"tag":84,"props":2727,"children":2728},{"style":112},[2729],{"type":37,"value":2730}," \u003C",{"type":32,"tag":84,"props":2732,"children":2733},{"style":127},[2734],{"type":37,"value":2735},"div",{"type":32,"tag":84,"props":2737,"children":2738},{"style":112},[2739],{"type":37,"value":2740},">Benvenuto {data.name}",{"type":32,"tag":84,"props":2742,"children":2743},{"style":101},[2744],{"type":37,"value":2745},"\u003C\u002F",{"type":32,"tag":84,"props":2747,"children":2748},{"style":112},[2749],{"type":37,"value":2735},{"type":32,"tag":84,"props":2751,"children":2752},{"style":101},[2753],{"type":37,"value":2754},">",{"type":32,"tag":84,"props":2756,"children":2757},{"style":112},[2758],{"type":37,"value":911},{"type":32,"tag":84,"props":2760,"children":2761},{"class":86,"line":514},[2762],{"type":32,"tag":84,"props":2763,"children":2764},{"style":112},[2765],{"type":37,"value":870},{"type":32,"tag":33,"props":2767,"children":2768},{},[2769],{"type":37,"value":2770},"Con questo setup, l'80% dell'HTML viene servito staticamente dalla CDN (TTFB 8-12ms), il 20% viene renderizzato in edge (30-40ms aggiuntivi). TTFB totale 40-50ms. La stessa pagina con full SSR origin-based tornava in 180-220ms.",{"type":32,"tag":33,"props":2772,"children":2773},{},[2774,2779],{"type":32,"tag":924,"props":2775,"children":2776},{},[2777],{"type":37,"value":2778},"Miglioramento con Streaming SSR:",{"type":37,"value":2780}," Grazie a React 18 e al meccanismo Suspense, restituisci immediatamente la parte statica, quindi lo streaming della parte SSR edge. Il browser inizia a parsare l'HTML, l'utente vede il contenuto a 20ms, il widget personalizzato viene \"idratato\" 30ms dopo. La latenza percepita cala a 20ms.",{"type":32,"tag":40,"props":2782,"children":2784},{"id":2783},"scenario-produzione-come-è-stato-mantenuto-40ms",[2785],{"type":37,"value":2786},"Scenario Produzione: Come È Stato Mantenuto 40ms",{"type":32,"tag":33,"props":2788,"children":2789},{},[2790],{"type":37,"value":2791},"Caso reale: sito e-commerce basato su Shopify Hydrogen, Cloudflare Workers + KV. Latenza iniziale 210ms (origine Francoforte, utente Istanbul), target sub-50ms.",{"type":32,"tag":33,"props":2793,"children":2794},{},[2795],{"type":32,"tag":924,"props":2796,"children":2797},{},[2798],{"type":37,"value":2799},"Ottimizzazioni applicate:",{"type":32,"tag":2801,"props":2802,"children":2803},"ol",{},[2804,2821,2845,2855],{"type":32,"tag":934,"props":2805,"children":2806},{},[2807,2812,2814,2820],{"type":32,"tag":924,"props":2808,"children":2809},{},[2810],{"type":37,"value":2811},"Riduzione della struttura dati KV:",{"type":37,"value":2813}," Il JSON del contesto utente è stato compresso da 2.4KB a 800 byte — solo campi critici (userId, cart, priceTier). I prodotti visualizzati di recente sono stati spostati su una key separata (",{"type":32,"tag":80,"props":2815,"children":2817},{"className":2816},[],[2818],{"type":37,"value":2819},"user:{id}:recent",{"type":37,"value":846},{"type":32,"tag":934,"props":2822,"children":2823},{},[2824,2829,2831,2836,2837,2843],{"type":32,"tag":924,"props":2825,"children":2826},{},[2827],{"type":37,"value":2828},"Riduzione bundle:",{"type":37,"value":2830}," Sostituisci React con Preact (3KB), ",{"type":32,"tag":80,"props":2832,"children":2834},{"className":2833},[],[2835],{"type":37,"value":1506},{"type":37,"value":1508},{"type":32,"tag":80,"props":2838,"children":2840},{"className":2839},[],[2841],{"type":37,"value":2842},"Intl.DateTimeFormat",{"type":37,"value":2844}," nativa. Il worker bundle è sceso da 180KB a 65KB.",{"type":32,"tag":934,"props":2846,"children":2847},{},[2848,2853],{"type":32,"tag":924,"props":2849,"children":2850},{},[2851],{"type":37,"value":2852},"Cache ibrida:",{"type":37,"value":2854}," Homepage statica (CDN cache 300s), solo il pulsante \"Add to Cart\" e i prezzi in edge SSR. Cache hit rate da 88% a 94%.",{"type":32,"tag":934,"props":2856,"children":2857},{},[2858,2863],{"type":32,"tag":924,"props":2859,"children":2860},{},[2861],{"type":37,"value":2862},"Selezione PoP edge:",{"type":37,"value":2864}," Abilitare la \"Smart Routing\" di Cloudflare — instrada da PoP con latenza minima verso l'utente. Gli utenti da Istanbul vengono serviti dal PoP di Sofia (22ms RTT), non da Francoforte.",{"type":32,"tag":33,"props":2866,"children":2867},{},[2868,2873],{"type":32,"tag":924,"props":2869,"children":2870},{},[2871],{"type":37,"value":2872},"Risultati:",{"type":37,"value":2874}," TTFB 210ms → 42ms (mediana), LCP 2.1s → 0.9s, INP 180ms → 95ms. Il tasso di conversione è salito da 2.3% a 2.9% (+26%). Il costo mensile del server di origine è sceso da $340 a $95 (costo edge $28\u002Fmese).",{"type":32,"tag":33,"props":2876,"children":2877},{},[2878],{"type":37,"value":2879},"L'ascesa della Edge SSR accelera nel 2026 — Cloudflare, Vercel, Fastly promettono tutti latenza sub-50ms. Quando configuri correttamente l'architettura KV store, la personalizzazione non ha bisogno di toccare l'origine. I trade-off esistono: limiti di bundle size, difficoltà di debug, rischio di eventual consistency. Ma nei scenari giusti — e-commerce, dashboard, SaaS — il guadagno è senza compromessi. 40ms di latenza non è più lusso, è lo standard.",{"type":32,"tag":2881,"props":2882,"children":2883},"style",{},[2884],{"type":37,"value":2885},"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":16,"searchDepth":118,"depth":118,"links":2887},[2888,2889,2892,2893,2894,2895],{"id":42,"depth":97,"text":45},{"id":63,"depth":97,"text":66,"children":2890},[2891],{"id":969,"depth":118,"text":972},{"id":1477,"depth":97,"text":1480},{"id":1605,"depth":97,"text":1608},{"id":2273,"depth":97,"text":2276},{"id":2783,"depth":97,"text":2786},"markdown","content:it:tech:edge-ssr-ridurre-latenza-personalizzazione-40ms.md","content","it\u002Ftech\u002Fedge-ssr-ridurre-latenza-personalizzazione-40ms.md","it\u002Ftech\u002Fedge-ssr-ridurre-latenza-personalizzazione-40ms","md",1785967479424]