configure-cache-busting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to Use This Skill
何时使用此技能
| Use this skill when... | Use another approach when... |
|---|---|
| Configuring content hashing for Next.js or Vite builds | Optimizing server-side caching (nginx, CDN config directly) |
| Setting up CDN cache headers for Vercel or Cloudflare | Debugging build output issues (system-debugging agent) |
| Verifying cache-busting compliance after a framework upgrade | Configuring general CI/CD workflows ( |
| Adding build verification scripts for hashed assets | Setting up container builds ( |
| Auditing static asset caching strategy across a project | Profiling frontend performance (browser devtools) |
| 适用场景 | 适用其他方案的场景 |
|---|---|
| 为Next.js或Vite构建配置内容哈希 | 优化服务器端缓存(直接配置Nginx、CDN) |
| 为Vercel或Cloudflare设置CDN缓存头 | 调试构建输出问题(使用系统调试Agent) |
| 框架升级后验证缓存击穿合规性 | 配置通用CI/CD工作流( |
| 为哈希资源添加构建验证脚本 | 配置容器构建( |
| 审计项目中静态资源的缓存策略 | 分析前端性能(使用浏览器开发者工具) |
Context
上下文信息
- Project root: !
pwd - Package files: !
find . -maxdepth 1 -name 'package.json' 2>/dev/null - Next.js config: !
find . -maxdepth 1 -name 'next.config.*' 2>/dev/null - Vite config: !
find . -maxdepth 1 -name 'vite.config.*' 2>/dev/null - Build output: !
find . -maxdepth 1 -type d \( -name '.next' -o -name 'dist' -o -name 'out' \) 2>/dev/null - CDN config: !
find . -maxdepth 1 \( -name 'vercel.json' -o -name '_headers' -o -name '_redirects' \) 2>/dev/null && find public -maxdepth 1 -name '_headers' 2>/dev/null - Project standards: !
find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null
- 项目根目录: !
pwd - 包文件: !
find . -maxdepth 1 -name 'package.json' 2>/dev/null - Next.js配置文件: !
find . -maxdepth 1 -name 'next.config.*' 2>/dev/null - Vite配置文件: !
find . -maxdepth 1 -name 'vite.config.*' 2>/dev/null - 构建输出目录: !
find . -maxdepth 1 -type d \( -name '.next' -o -name 'dist' -o -name 'out' \) 2>/dev/null - CDN配置文件: !
find . -maxdepth 1 \( -name 'vercel.json' -o -name '_headers' -o -name '_redirects' \) 2>/dev/null && find public -maxdepth 1 -name '_headers' 2>/dev/null - 项目标准文件: !
find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null
Parameters
参数说明
Parse from command arguments:
- : Report compliance status without modifications (CI/CD mode)
--check-only - : Apply fixes automatically without prompting
--fix - : Override framework detection
--framework <nextjs|vite> - : Specify CDN provider for cache header configuration
--cdn <cloudflare|vercel|none>
从命令参数中解析:
- : 仅报告合规状态,不进行修改(CI/CD模式)
--check-only - : 自动应用修复,无需提示
--fix - : 覆盖框架自动检测结果
--framework <nextjs|vite> - : 指定用于缓存头配置的CDN提供商
--cdn <cloudflare|vercel|none>
Execution
执行流程
Execute this cache-busting configuration check:
执行以下缓存击穿配置检查:
Step 1: Detect project framework
步骤1:检测项目框架
Identify the framework from file structure:
| Indicator | Framework | Config File |
|---|---|---|
| Next.js | |
| Next.js | |
| Vite | |
| Next.js (built) | Detection only |
| Vite (built) | Detection only |
Check dependencies for or .
package.json"next""vite"If both detected, prompt user to specify with . If neither detected, report unsupported and exit.
--framework通过文件结构识别框架:
| 识别标识 | 框架 | 配置文件 |
|---|---|---|
| Next.js | |
| Next.js | |
| Vite | |
| Next.js(已构建) | 仅用于检测 |
| Vite(已构建) | 仅用于检测 |
检查的依赖项中是否包含或。
package.json"next""vite"如果同时检测到两个框架,将提示用户使用指定。如果都未检测到,将报告不支持并退出。
--frameworkStep 2: Analyze current cache-busting state
步骤2:分析当前缓存击穿状态
For the detected framework, read config files and check:
Next.js - Read and check:
next.config.js/ts- configured for deterministic builds
generateBuildId - configured for CDN
assetPrefix - enabled
compress: true - for security
poweredByHeader: false - configured
generateEtags - Cache headers configured in function
headers()
Vite - Read and check:
vite.config.js/ts- uses
build.rollupOptions.output.entryFileNames[hash] - uses
build.rollupOptions.output.chunkFileNames[hash] - uses
build.rollupOptions.output.assetFileNames[hash] - for SSR/manifest-based routing
build.manifest: true - configured appropriately
build.cssCodeSplit
针对检测到的框架,读取配置文件并检查:
Next.js - 读取并检查:
next.config.js/ts- 已配置以实现确定性构建
generateBuildId - 已配置用于CDN
assetPrefix - 已启用
compress: true - 已设置以提升安全性
poweredByHeader: false - 已配置
generateEtags - 已在函数中配置缓存头
headers()
Vite - 读取并检查:
vite.config.js/ts- 使用了
build.rollupOptions.output.entryFileNames[hash] - 使用了
build.rollupOptions.output.chunkFileNames[hash] - 使用了
build.rollupOptions.output.assetFileNames[hash] - 用于SSR/基于清单的路由
build.manifest: true - 已合理配置
build.cssCodeSplit
Step 3: Detect CDN provider
步骤3:检测CDN提供商
Identify CDN from project files:
| Indicator | CDN Provider |
|---|---|
| Vercel |
| Vercel |
| Cloudflare Pages |
| Cloudflare Pages / Netlify |
| Cloudflare Workers/Pages |
| None of the above | Generic / None |
通过项目文件识别CDN:
| 识别标识 | CDN提供商 |
|---|---|
存在 | Vercel |
存在 | Vercel |
根目录或 | Cloudflare Pages |
存在 | Cloudflare Pages / Netlify |
存在 | Cloudflare Workers/Pages |
| 以上都不存在 | 通用/无CDN |
Step 4: Generate compliance report
步骤4:生成合规性报告
Print a formatted compliance report:
Cache-Busting Compliance Report
================================
Project: [name]
Framework: [Next.js 14.x | Vite 5.x]
CDN Provider: [Vercel | Cloudflare | None detected]
Framework Configuration:
Config file next.config.js [EXISTS | MISSING]
Asset hashing [hash] in filenames [ENABLED | DISABLED]
Build manifest manifest files [GENERATED | MISSING]
Deterministic builds Build ID configured [PASS | NOT SET]
Compression gzip/brotli enabled [PASS | DISABLED]
Cache Headers:
Static assets immutable, 1y [CONFIGURED | MISSING]
HTML files no-cache, must-revalidate [CONFIGURED | MISSING]
API routes varies by route [CONFIGURED | N/A]
CDN configuration vercel.json/_headers [EXISTS | MISSING]
Build Output (if built):
Hashed filenames app.[hash].js [DETECTED | NOT BUILT]
Content addressing Unique hashes per version [PASS | DUPLICATE]
Manifest integrity Valid manifest.json [PASS | INVALID]
Overall: [X issues found]
Recommendations:
[List specific fixes needed]If , stop here.
--check-only打印格式化的合规性报告:
缓存击穿合规性报告
================================
项目: [名称]
框架: [Next.js 14.x | Vite 5.x]
CDN提供商: [Vercel | Cloudflare | 未检测到]
框架配置:
配置文件 next.config.js [已存在 | 缺失]
资源哈希 文件名中包含[hash] [已启用 | 未启用]
构建清单 清单文件 [已生成 | 缺失]
确定性构建 已配置Build ID [通过 | 未设置]
压缩 已启用gzip/brotli [通过 | 未启用]
缓存头:
静态资源 immutable, 1y [已配置 | 缺失]
HTML文件 no-cache, must-revalidate [已配置 | 缺失]
API路由 因路由而异 [已配置 | 不适用]
CDN配置 vercel.json/_headers [已存在 | 缺失]
构建输出(若已构建):
哈希文件名 app.[hash].js [已检测到 | 未构建]
内容寻址 每个版本对应唯一哈希 [通过 | 重复]
清单完整性 有效的manifest.json [通过 | 无效]
总体情况: [发现X个问题]
建议:
[列出需要修复的具体内容]如果使用参数,在此步骤停止。
--check-onlyStep 5: Apply configuration (if --fix or user confirms)
步骤5:应用配置(若使用--fix或用户确认)
Based on detected framework, create or update config files using templates from REFERENCE.md:
- Next.js: Update with deterministic builds, compression, cache headers
next.config.js/ts - Vite: Update with content hashing, manifest, chunk splitting
vite.config.js/ts
根据检测到的框架,使用REFERENCE.md中的模板创建或更新配置文件:
- Next.js: 更新,配置确定性构建、压缩、缓存头
next.config.js/ts - Vite: 更新,配置内容哈希、清单、代码分割
vite.config.js/ts
Step 6: Configure CDN cache headers
步骤6:配置CDN缓存头
Based on detected CDN provider, create or update cache header configuration using templates from REFERENCE.md:
- Vercel: Create/update with header rules
vercel.json - Cloudflare Pages: Create with cache rules
public/_headers - Generic: Provide nginx configuration reference
根据检测到的CDN提供商,使用REFERENCE.md中的模板创建或更新缓存头配置:
- Vercel: 创建/更新,添加头规则
vercel.json - Cloudflare Pages: 创建,添加缓存规则
public/_headers - 通用: 提供Nginx配置参考
Step 7: Add build verification
步骤7:添加构建验证
Create to verify content hashing works after build. Add scripts for build verification. Use the verification script template from REFERENCE.md.
scripts/verify-cache-busting.jspackage.json创建,用于验证构建后内容哈希是否正常工作。在中添加构建验证脚本。使用REFERENCE.md中的验证脚本模板。
scripts/verify-cache-busting.jspackage.jsonStep 8: Configure CI/CD verification
步骤8:配置CI/CD验证
Add cache-busting verification step to GitHub Actions workflow. Use the CI workflow template from REFERENCE.md.
在GitHub Actions工作流中添加缓存击穿验证步骤。使用REFERENCE.md中的CI工作流模板。
Step 9: Update standards tracking
步骤9:更新标准跟踪
Update :
.project-standards.yamlyaml
standards_version: "2025.1"
last_configured: "[timestamp]"
components:
cache-busting: "2025.1"
cache-busting-framework: "[nextjs|vite]"
cache-busting-cdn: "[vercel|cloudflare|none]"
cache-busting-verified: true更新:
.project-standards.yamlyaml
standards_version: "2025.1"
last_configured: "[时间戳]"
components:
cache-busting: "2025.1"
cache-busting-framework: "[nextjs|vite]"
cache-busting-cdn: "[vercel|cloudflare|none]"
cache-busting-verified: trueStep 10: Print final report
步骤10:打印最终报告
Print a summary of changes applied, cache strategy overview, and next steps for verification.
For detailed configuration templates and code examples, see REFERENCE.md.
打印已应用更改的摘要、缓存策略概述,以及后续的验证步骤。
有关详细的配置模板和代码示例,请参阅REFERENCE.md。
Agentic Optimizations
Agent优化命令
| Context | Command |
|---|---|
| Quick compliance check | |
| Auto-fix all issues | |
| Next.js project only | |
| Vite project only | |
| Cloudflare CDN headers | |
| Vercel CDN headers | |
| 场景 | 命令 |
|---|---|
| 快速合规性检查 | |
| 自动修复所有问题 | |
| 仅针对Next.js项目 | |
| 仅针对Vite项目 | |
| Cloudflare CDN头配置 | |
| Vercel CDN头配置 | |
Output
输出内容
Provide:
- Compliance report with framework and CDN configuration status
- List of changes made (if --fix) or proposed (if interactive)
- Verification instructions and commands
- CDN cache header examples
- Next steps for deployment and monitoring
提供:
- 包含框架和CDN配置状态的合规性报告
- 已更改的内容列表(若使用--fix)或建议的更改(若交互式)
- 验证说明和命令
- CDN缓存头示例
- 部署和监控的后续步骤
See Also
另请参阅
- - Run all compliance checks
/configure:all - - Quick compliance overview
/configure:status - - GitHub Actions workflow standards
/configure:workflows - - Container configuration with build caching
/configure:dockerfile - Next.js Documentation - https://nextjs.org/docs/pages/api-reference/next-config-js
- Vite Documentation - https://vitejs.dev/config/build-options.html
- Web.dev Caching Guide - https://web.dev/http-cache/
- - 运行所有合规性检查
/configure:all - - 快速查看合规性概述
/configure:status - - GitHub Actions工作流标准
/configure:workflows - - 带构建缓存的容器配置
/configure:dockerfile - Next.js官方文档 - https://nextjs.org/docs/pages/api-reference/next-config-js
- Vite官方文档 - https://vitejs.dev/config/build-options.html
- Web.dev缓存指南 - https://web.dev/http-cache/