{"record":{"id":"98975faf07b17b30","repo":"sveltejs/kit","slug":"invalid-cache-control-directive-invalid-did","errorCode":null,"errorMessage":"Invalid cache-control directive \"${invalid}\". Did you mean one of: ${[...VALID_CACHE_CONTROL_DIRECTIVES].join(', ')}? ${error_suffix}","messagePattern":"Invalid cache-control directive \"(.+?)\"\\. Did you mean one of: (.+?)\\? (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/server/validate-headers.js","lineNumber":35,"sourceCode":"\t'min-fresh'\n]);\n\nconst CONTENT_TYPE_PATTERN =\n\t/^(application|audio|example|font|haptics|image|message|model|multipart|text|video|x-[a-z]+)\\/[-+.\\w]+$/i;\n\n/** @type {Record<string, (value: string) => void>} */\nconst HEADER_VALIDATORS = {\n\t'cache-control': (value) => {\n\t\tconst error_suffix = `(While parsing \"${value}\".)`;\n\t\tconst parts = value.split(',').map((part) => part.trim());\n\t\tif (parts.some((part) => !part)) {\n\t\t\tthrow new Error(`\\`cache-control\\` header contains empty directives. ${error_suffix}`);\n\t\t}\n\n\t\tconst directives = parts.map((part) => part.split('=')[0].toLowerCase());\n\t\tconst invalid = directives.find((directive) => !VALID_CACHE_CONTROL_DIRECTIVES.has(directive));\n\t\tif (invalid) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid cache-control directive \"${invalid}\". Did you mean one of: ${[...VALID_CACHE_CONTROL_DIRECTIVES].join(', ')}? ${error_suffix}`\n\t\t\t);\n\t\t}\n\t},\n\n\t'content-type': (value) => {\n\t\tconst type = value.split(';')[0].trim();\n\t\tconst error_suffix = `(While parsing \"${value}\".)`;\n\t\tif (!CONTENT_TYPE_PATTERN.test(type)) {\n\t\t\tthrow new Error(`Invalid content-type value \"${type}\". ${error_suffix}`);\n\t\t}\n\t}\n};\n\n/**\n * @param {Record<string, string>} headers\n */\nexport function validateHeaders(headers) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/validate-headers.js#L17-L53","documentation":"Header validation applied to cache-control values set by the app: each comma-separated directive (the part before '=') is checked against the known cache-control directive set, and an unrecognized token triggers this error, including the offending token, the valid list, and a hint that it may be a typo.","triggerScenarios":"setHeaders({ 'cache-control': 'max-age=60, pulbic' }) (typo for public); using non-standard directives like 'immutable ' misspelled or 'no-cache-store'; camelCase variants like 'Max-Age' are lowercased and fine, but wrong words are not.","commonSituations":"Hand-typed cache policies with typos; copying CDN-specific directives (e.g. s-maxage is valid, but 'stale-if-error' must be spelled exactly) that the validator doesn't recognize.","solutions":["Correct the directive name to one from the listed valid set (no-store, no-cache, must-revalidate, public, private, max-age, s-maxage, immutable, stale-while-revalidate, etc.)","Split custom/proprietary directives out — SvelteKit only validates cache-control; use another header name for non-standard policies","Check spelling case-insensitively: the validator lowercases, so 'Pulbic' still fails"],"exampleFix":"// before\nevent.setHeaders({ 'cache-control': 'pulbic, max-age=3600' });\n// after\nevent.setHeaders({ 'cache-control': 'public, max-age=3600' });","handlingStrategy":"validation","validationCode":"const VALID = new Set(['no-store','no-cache','must-revalidate','proxy-revalidate','must-understand','immutable','public','private','max-age','s-maxage','max-stale','min-fresh','stale-while-revalidate','stale-if-error','only-if-cached','no-transform']);\nfunction validateCacheControl(value) {\n  for (const part of value.split(',')) {\n    const d = part.trim().split('=')[0].toLowerCase();\n    if (!VALID.has(d)) throw new Error('Invalid cache-control directive: ' + d);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  event.setHeaders({ 'cache-control': cc });\n} catch (e) {\n  if (e.message.startsWith('Invalid cache-control directive')) console.error('Typo in directive:', cc);\n}","preventionTips":["Keep a constant list of allowed directives in your codebase","Copy directive names from MDN rather than typing from memory","Note the validator lowercases input, so only spelling matters"],"tags":["cache-control","http-headers","validation"],"backgroundTag":"invalid-cache-control-header","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}