Skip to content

Commit

Permalink
Wrap conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Dec 22, 2024
1 parent 907cd5f commit 6b1b862
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/StaticCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ private function addCacheHeadersToWebResponse(): void
HeaderEnum::CACHE_CONTROL->value
);

// Cache in CDN, not in browser
if ($cacheControl) {
Craft::$app->getResponse()->getHeaders()->setDefault(
HeaderEnum::CDN_CACHE_CONTROL->value,
$cacheControl,
);
}

// Enable ESI processing
// Note: The Surrogate-Control header will cause Cloudflare to ignore
// the Cache-Control header: https://developers.cloudflare.com/cache/concepts/cdn-cache-control/#header-precedence
Expand All @@ -232,14 +240,6 @@ private function addCacheHeadersToWebResponse(): void
'content="ESI/1.0"',
);

// Cache in CDN, not in browser
Craft::$app->getResponse()->getHeaders()->setDefault(
HeaderEnum::CDN_CACHE_CONTROL->value,
$cacheControl,
);



// Capture, remove any existing headers so we can prepare them
$existingTagsFromHeader = Collection::make($headers->get(HeaderEnum::CACHE_TAG->value, first: false) ?? []);
$headers->remove(HeaderEnum::CACHE_TAG->value);
Expand Down

0 comments on commit 6b1b862

Please sign in to comment.