From 49b26bd375eeef67aece1274ab51f192216fc1b6 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 24 Sep 2019 10:38:41 +0200 Subject: [PATCH] Return a `Cache-Control` header for files served via the API --- changelog/53_UNRELEASED_2019-xx-xx.md | 1 + controllers/FilesApiController.php | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog/53_UNRELEASED_2019-xx-xx.md b/changelog/53_UNRELEASED_2019-xx-xx.md index 84bc90a1..39ad9375 100644 --- a/changelog/53_UNRELEASED_2019-xx-xx.md +++ b/changelog/53_UNRELEASED_2019-xx-xx.md @@ -2,4 +2,5 @@ - It's now possible to display a recipe directly from the meal plan (new "eye button") (thanks @kriddles) - Improved the responsiveness of the meal plan and calendar page by automatically switching to a day calendar view on smaller screens (thanks for the idea @kriddles) - The calendar now also contains all planned recipes from the meal plan on the corresponding day +- The API Endpoint `GET /files/{group}/{fileName}` now also returns a `Cache-Control` header (defaults fixed to 30 days) to further increase page load times - Some style/CSS detail-refinements diff --git a/controllers/FilesApiController.php b/controllers/FilesApiController.php index 29c4b98f..91504a49 100644 --- a/controllers/FilesApiController.php +++ b/controllers/FilesApiController.php @@ -81,6 +81,7 @@ class FilesApiController extends BaseApiController if (file_exists($filePath)) { $response->write(file_get_contents($filePath)); + $response = $response->withHeader('Cache-Control', 'max-age=2592000'); $response = $response->withHeader('Content-Type', mime_content_type($filePath)); return $response->withHeader('Content-Disposition', 'inline; filename="' . $fileName . '"'); }