← 中文资源

简体中文版本

HTTP 缓存头工作流

为静态资源和 API 响应配置 HTTP 缓存头,提升性能并减少服务器负载。

阅读英文原文

概述

HTTP 缓存头工作流是一个初级难度的工作流。为静态资源和 API 响应配置 HTTP 缓存头,提升性能并减少服务器负载。该工作流的目标是:Set appropriate cache headers to optimize loading performance.

环境准备

执行本工作流需要以下环境:A web server or CDN configuration access;Understanding of Cache-Control and ETag headers;Static assets and API endpoints to configure。请确保在开始前准备好所有必需的工具和资源,以避免中途因环境问题中断。

执行步骤

本工作流包含4个步骤。步骤1:Identify cacheable resources——List static assets and API responses that can be safely cached. 步骤2:Set static asset headers——Configure long-lived cache headers with fingerprinted filenames for static assets. 步骤3:Set API response headers——Configure appropriate cache headers for API responses, using ETag or Last-Modified. 步骤4:Verify with curl——Use curl -I to inspect the headers returned for each resource.

验证与清理

预期结果:All cacheable resources have appropriate cache headers, verified with curl.。验证方法:Run curl -I for each resource type and confirm the cache headers match the intended strategy.。清理操作:No cleanup needed; cache configuration should be committed.。estimatedMinutes 为 20 分钟。

代码示例

curl -I https://example.com/static/app.abc123.js
# Should show: Cache-Control: public, max-age=31536000, immutable