From 53db86293f3691532c7c4ce7febca1f1be86f9fd Mon Sep 17 00:00:00 2001 From: Samuel CHEMLA Date: Sat, 20 Oct 2018 18:49:04 +0200 Subject: [PATCH] Add cache header for static assets --- src/Middleware/StaticContent.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Middleware/StaticContent.php b/src/Middleware/StaticContent.php index 39b6d36..f5d6665 100644 --- a/src/Middleware/StaticContent.php +++ b/src/Middleware/StaticContent.php @@ -75,7 +75,9 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) if ($realPath !== false && strpos($realPath, $this->publicPath) === 0 && is_file($realPath)) { $extension = pathinfo($realPath, PATHINFO_EXTENSION); $mime = $this->mimeDb->getFromExtension($extension); - $headers = []; + $headers = [ + 'Cache-Control' => 'public, max-age=31536000' //1 year of cache, make sure you change URLs when changing resources + ]; if ($mime !== null) { $headers['Content-Type'] = $mime['name']; }