Next.js 부분 사전 가져오기

Next.js Partial Prefetching

Next.js 16.3은 이동할 경로의 재사용 가능한 로딩 셸을 미리 가져와 클릭 즉시 표시합니다.

···
html
<section class="stage"><div class="heading">PARTIAL PREFETCH <span class="hint">shell before click</span></div><div class="prefetch-screen"><div class="prefetch-link">OPEN ARTICLE</div><div class="prefetch-page"><div class="prefetch-top">ARTICLE</div><div class="prefetch-lines"><i></i><i></i></div><div class="prefetch-slot" id="prefetch-slot">pending</div></div></div><div class="prefetch-readout" id="prefetch-readout">Shell is prefetched in the background</div><div class="caption">Click shows the shell; content follows</div></section>
css
.stage{width:min(94vw,780px);height:min(88vh,322px);padding:clamp(12px,3vmin,20px);border:1px solid var(--line);border-radius:16px;background:var(--surface);box-shadow:0 12px 36px #0001;display:flex;flex-direction:column;gap:clamp(7px,2vmin,14px);font:500 clamp(12px,3.5vmin,17px)/1.3 var(--font-sans,system-ui,sans-serif);overflow:hidden}.heading{display:flex;justify-content:space-between;align-items:center;gap:8px;font-weight:750;color:var(--accent)}.hint{color:var(--muted);font-size:clamp(12px,3.2vmin,14px);font-weight:500}.caption{margin-top:auto;color:var(--muted);font-size:clamp(12px,3.2vmin,14px)}.row{display:flex;gap:clamp(5px,1.5vmin,12px);align-items:center}.tile{padding:clamp(6px,1.8vmin,13px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center;min-width:0}.arrow{color:var(--accent);font-weight:800}.stage [data-on]{transition:background .3s,border-color .3s,opacity .3s,transform .3s}.stage .on{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--surface));color:var(--accent)}.prefetch-screen{flex:1;display:flex;align-items:center;justify-content:center;gap:clamp(6px,2vmin,18px);min-height:70px}.prefetch-link{width:36%;max-width:175px;border:1px solid var(--accent-2);border-radius:7px;background:var(--bg);padding:9px 4px;text-align:center;color:var(--accent-2);font-weight:750;font-size:clamp(12px,3vmin,15px)}.prefetch-page{width:52%;max-width:220px;border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:8px;opacity:.35;transition:opacity .3s,border-color .3s}.prefetch-top{font-weight:750;color:var(--accent)}.prefetch-lines{margin:8px 0}.prefetch-lines i{display:block;height:6px;background:var(--line);border-radius:6px;margin:5px 0}.prefetch-lines i:last-child{width:65%}.prefetch-slot{border:1px dashed var(--accent-3);border-radius:5px;color:var(--muted);padding:4px;text-align:center;font-size:clamp(12px,3vmin,14px)}.stage[data-step="1"] .prefetch-page,.stage[data-step="2"] .prefetch-page{opacity:1;border-color:var(--accent)}.stage[data-step="2"] .prefetch-slot{border-style:solid;border-color:var(--accent);color:var(--accent)}.prefetch-readout{text-align:center;color:var(--accent-2);font-size:clamp(12px,3vmin,14px);font-weight:700}.stage small,.stage button,.stage .cards b,.stage .phase b,.stage .pair b,.stage .tree-mini b{font-size:clamp(12px,3.2vmin,14px)!important}
js
const stage=document.querySelector(".stage"),slot=document.getElementById("prefetch-slot"),readout=document.getElementById("prefetch-readout"),notes=["Shell is prefetched in the background","Click: shell appears immediately","Dynamic content streams in"];let step=0;function tick(){stage.dataset.step=String(step);slot.textContent=step===2?"full story":"pending";readout.textContent=notes[step];step=(step+1)%3}tick();const timer=setInterval(tick,1050);stage.addEventListener("pointerdown",()=>{clearInterval(timer);tick()})

Next.js 16.3의 Partial Prefetching은 대상 경로 UI에서 재사용 가능한 로딩 셸을 추출해 방문 전에 클라이언트로 가져옵니다. 사용자가 링크를 누르면 셸을 즉시 보여주고 나머지 동적 콘텐츠는 이어서 받습니다.

기존 세그먼트별 점진 사전 가져오기가 어떤 경로 조각을 가져올지 결정한다면, 이 기능은 해당 경로의 UI를 어디까지 미리 준비할지 조절합니다. Cache Components와 partialPrefetching 설정이 필요합니다.

언제 쓰나

서버 중심 Next.js 앱에서 링크 클릭 직후 로딩 셸을 보여주고 나머지 콘텐츠를 스트리밍할 때 사용합니다.

페이지로 열기 ↗