diff --git a/packages/hint-http-cache/src/hint.ts b/packages/hint-http-cache/src/hint.ts index 1fbdbc48d96..145c91026f5 100644 --- a/packages/hint-http-cache/src/hint.ts +++ b/packages/hint-http-cache/src/hint.ts @@ -123,6 +123,11 @@ export default class HttpCacheHint implements IHint { const parsedCacheControlHeader = usedDirectives.reduce((parsed: ParsedDirectives, current: string) => { const [directive, value] = current.split('='); + // Empty string, e.g. `cache-control: max-age=12345,` --> `['max-age=123456', '']` + if (!directive) { + return parsed; + } + // Validate directive with value. E.g.: max-age= if (directive && value) { /* diff --git a/packages/hint-http-cache/tests/tests.ts b/packages/hint-http-cache/tests/tests.ts index 7e4d22a00d9..c493d967266 100644 --- a/packages/hint-http-cache/tests/tests.ts +++ b/packages/hint-http-cache/tests/tests.ts @@ -178,6 +178,17 @@ const defaultTests: HintTest[] = [ } } }, + { + name: `Asset with "Cache-Control: max-age=31536000," header fails`, + reports: [{ message: 'Static resources should use the "immutable" directive:\nDirectives used: max-age=31536000,' }], + serverConfig: { + '/': generateHTMLPage(''), + '/favicon.123.ico': { + content: '', + headers: { 'Cache-Control': 'max-age=31536000,' } + } + } + }, { name: 'JS with "Cache-Control: no-cache" fails', reports: [