Skip to content

Commit

Permalink
Add cache header for static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
phpbg committed Oct 20, 2018
1 parent e561ba0 commit 53db862
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Middleware/StaticContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down

0 comments on commit 53db862

Please sign in to comment.