ETag conditional request

ETag 조건부 요청

A stored version tag lets the server return 304 without a body when content has not changed.

···
html
<div class="n-demo"><div class="n-head"><strong>ETAG REVALIDATION</strong><span>LIVE TRACE</span></div><div class="n-stage"><div class="etag"><div class="etag-tags"><span class="n-box mono">If-None-Match: v1</span><span id="etag-server" class="n-box mono">server: v1</span></div><div id="etag-status" class="etag-status">304 Not Modified</div><div class="etag-body"><span>response body</span><i id="etag-bar"></i></div></div></div><div class="n-foot">tap to step · auto replay</div></div>
css
.n-demo{width:min(94vw,760px);height:min(88vh,324px);padding:clamp(9px,2.2vmin,18px);border:1px solid var(--line);border-radius:13px;background:var(--surface);display:flex;flex-direction:column;gap:clamp(5px,1.3vmin,10px);font:600 clamp(12px,2.4vmin,16px)/1.3 "Pretendard Variable",Pretendard,-apple-system,BlinkMacSystemFont,"Apple SD Gothic Neo",sans-serif;overflow:hidden}.n-head,.n-foot{display:flex;justify-content:space-between;align-items:center;color:var(--muted)}.n-head strong{color:var(--accent)}.n-head span,.n-foot{font-size:12px}.n-stage{flex:1;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;gap:clamp(4px,1vmin,10px)}.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.n-box{padding:clamp(5px,1.5vmin,11px);border:1px solid var(--line);border-radius:8px;background:var(--bg);text-align:center}.n-on{border-color:var(--accent)!important;color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important}.n-muted{color:var(--muted)}@media(max-width:400px){.n-head span{display:none}}.etag{width:94%;display:grid;gap:12px}.etag-tags{display:flex;gap:8px;justify-content:space-between}.etag-tags .n-box{min-width:46%;padding:7px 3px}.etag-status{text-align:center;color:var(--accent)}.etag-body{display:flex;align-items:center;gap:7px;color:var(--muted)}.etag-body i{display:block;height:17px;border-radius:4px;background:var(--accent);transition:width .4s;width:0}
js
let changed=false;function advance(){changed=!changed;document.getElementById('etag-server').textContent=changed?'server: v2':'server: v1';document.getElementById('etag-status').textContent=changed?'200 OK · new version':'304 Not Modified';document.getElementById('etag-bar').style.width=changed?'48%':'0'}
const clickTarget=document.querySelector('.n-demo');if(clickTarget&&typeof advance==='function'){advance();const timer=setInterval(advance,1050);clickTarget.addEventListener('pointerdown',()=>{clearInterval(timer);advance()})}

A server can identify a representation with an ETag. The client sends If-None-Match on a later request; if the tag still matches, a 304 allows reuse of the stored response.

The demo removes the body on a matching tag and sends a new body with 200 after a change. An ETag identifies a representation version; it need not be a hash.

When to use

Use conditional requests to reduce transfer for resources checked often but changed occasionally.

Open as page ↗