Add cache headers to assets

This commit is contained in:
Giuseppe Criscione 2024-11-01 19:30:25 +01:00
parent 6f43d30b84
commit fd60bed3a7
3 changed files with 4 additions and 3 deletions

View File

@ -14,7 +14,7 @@ class AssetController extends AbstractController
$path = FileSystem::joinPaths($this->config->get('system.images.processPath'), $routeParams->get('id'), $routeParams->get('name'));
if (FileSystem::isFile($path)) {
return new FileResponse($path);
return new FileResponse($path, headers: ['Cache-Control' => 'private, max-age=31536000, immutable']);
}
throw new FileNotFoundException('Cannot find asset');

View File

@ -85,7 +85,8 @@ class PageController extends AbstractController
}
if ((($parent = $this->site->findPage($upperLevel)) !== null) && $parent->files()->has($filename)) {
return new FileResponse($parent->files()->get($filename)->path());
$file = $parent->files()->get($filename);
return new FileResponse($file->path(), headers: ['ETag' => $file->hash(), 'Last-Modified' => gmdate('D, d M Y H:i:s T', $file->lastModifiedTime())]);
}
}

View File

@ -218,7 +218,7 @@ class UsersController extends AbstractController
$path = FileSystem::joinPaths($this->config->get('system.users.paths.images'), $routeParams->get('image'));
if (FileSystem::isFile($path)) {
return new FileResponse($path, headers: ['Cache-Control' => 'max-age=31536000, private']);
return new FileResponse($path, headers: ['Cache-Control' => 'private, max-age=31536000, immutable']);
}
throw new FileNotFoundException('Cannot find asset');