0Pricing
Caching Strategies: Redis + CDN + Edge Computing · 강의

엣지 함수 트리거 및 요청 수명 주기

엣지 함수가 요청 수명 주기에 연결되는 위치와 엣지에서 요청과 응답을 수정할 수 있게 하는 트리거 지점을 이해합니다.

엣지 함수 트리거 및 요청 수명 주기은(는) CoddyKit의 무료 Caching Strategies: Redis + CDN + Edge Computing 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Caching Strategies: Redis + CDN + Edge Computing 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Caching Strategies: Redis + CDN + Edge Computing 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

The Edge Request Lifecycle

When a request reaches a CDN edge, it passes through distinct phases. Edge functions can attach to specific phases to inspect or transform the request and response.

  • Viewer request: as the request arrives
  • Origin request: before fetching from origin
  • Origin response: after origin replies
  • Viewer response: before returning to the user

Viewer Request Trigger

The viewer request trigger runs on every incoming request, even cache hits. Use it for lightweight logic like redirects, header normalization, or A/B routing.

Origin Request Trigger

The origin request trigger runs only on cache misses, just before the edge contacts the origin. It is ideal for rewriting the origin path or choosing a different backend.

function handler(event) {
  var req = event.request;
  req.uri = "/v2" + req.uri;
  return req;
}

Origin Response Trigger

The origin response trigger fires after the origin replies but before the response is cached. Use it to adjust cache headers or inject security headers.

Viewer Response Trigger

The viewer response trigger runs before the response goes to the user, on both hits and misses. Use it for final header tweaks like adding CORS or HSTS.

function handler(event) {
  var res = event.response;
  res.headers["x-edge"] = { value: "true" };
  return res;
}

Triggers and the Cache

Knowing which triggers run on cache hits matters for performance and cost. Viewer triggers run every time; origin triggers run only on misses. Put heavy logic on origin triggers to avoid paying for it on every hit.

Short-Circuiting a Request

An edge function can return a response directly instead of forwarding it, short-circuiting the lifecycle. This is great for maintenance pages, auth gates, or geo-blocks.

function handler(event) {
  var country = event.request.headers["cloudfront-viewer-country"];
  if (country && country.value === "XX") {
    return { statusCode: 403, body: "Blocked" };
  }
  return event.request;
}

Modifying Requests vs Responses

Request triggers can change the URI, headers, and query string before routing. Response triggers can change status codes and headers. Choose the trigger that matches what you need to mutate.

Performance Constraints

Edge functions run inside tight limits on CPU time and memory because they execute on every request at scale. Keep them small, avoid network calls in viewer triggers, and prefer synchronous logic.

  • Tiny scripts equal predictable latency
  • Heavy logic belongs on origin triggers or full edge runtimes

Choosing the Right Trigger

A quick decision guide:

  • Redirect or auth gate: viewer request
  • Rewrite origin path: origin request
  • Adjust cache TTL: origin response
  • Add response headers for everyone: viewer response

Debugging Lifecycle Triggers

Test each trigger in isolation. Log the phase and inspect headers added by the CDN (like the viewer country) to confirm your function runs where you expect.

Quick Check

Confirm your understanding of edge trigger points.

Recap

You learned the four edge function trigger points across the request lifecycle: viewer request, origin request, origin response, and viewer response. You saw which run on cache hits versus misses, how to short-circuit a request, and how to pick the right trigger while respecting edge runtime limits.

자주 묻는 질문

“엣지 함수 트리거 및 요청 수명 주기” 강의는 무료인가요?

네 — “엣지 함수 트리거 및 요청 수명 주기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Caching Strategies: Redis + CDN + Edge Computing 강의 전체를 잠금 해제할 수 있습니다. Caching Strategies: Redis + CDN + Edge Computing 강의에는 총 4개의 강의가 포함되어 있습니다.

“엣지 함수 트리거 및 요청 수명 주기”에서 뭘 배우나요?

엣지 함수가 요청 수명 주기에 연결되는 위치와 엣지에서 요청과 응답을 수정할 수 있게 하는 트리거 지점을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Caching Strategies: Redis + CDN + Edge Computing을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Caching Strategies: Redis + CDN + Edge Computing을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Caching Strategies: Redis + CDN + Edge Computing은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“엣지 함수 트리거 및 요청 수명 주기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Caching Strategies: Redis + CDN + Edge Computing 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Caching Strategies: Redis + CDN + Edge Computing 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 동적 콘텐츠를 위한 에지 캐싱
  2. 에지의 서버리스 함수
  3. 에지 함수 배포
  4. 엣지 함수 트리거 및 요청 수명 주기
← Caching Strategies: Redis + CDN + Edge Computing(으)로 돌아가기