summaryrefslogtreecommitdiffstats
path: root/core/Controller/JsController.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-16 22:45:31 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-03-19 14:21:53 +0100
commit796b4f19f8f8f8a989e122fd603ce8db9daa0fc7 (patch)
treeeee62aa6418723d1547040862f71accbac20f615 /core/Controller/JsController.php
parent9834f33d56f64f63b0f05c149418b2c83d5fa37d (diff)
downloadnextcloud-server-796b4f19f8f8f8a989e122fd603ce8db9daa0fc7.tar.gz
nextcloud-server-796b4f19f8f8f8a989e122fd603ce8db9daa0fc7.zip
Add Cache-control: immutable
Cache generated CSS forever! Also cache combined JS forever Fix tests Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/Controller/JsController.php')
-rw-r--r--core/Controller/JsController.php21
1 files changed, 11 insertions, 10 deletions
diff --git a/core/Controller/JsController.php b/core/Controller/JsController.php
index 670ca997257..3fc48e9a380 100644
--- a/core/Controller/JsController.php
+++ b/core/Controller/JsController.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -29,6 +30,7 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
@@ -44,12 +46,6 @@ class JsController extends Controller {
/** @var ITimeFactory */
protected $timeFactory;
- /**
- * @param string $appName
- * @param IRequest $request
- * @param Factory $appDataFactory
- * @param ITimeFactory $timeFactory
- */
public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) {
parent::__construct($appName, $request);
@@ -65,7 +61,7 @@ class JsController extends Controller {
* @param string $appName css folder name
* @return FileDisplayResponse|NotFoundResponse
*/
- public function getJs($fileName, $appName) {
+ public function getJs(string $fileName, string $appName): Response {
try {
$folder = $this->appData->getFolder($appName);
$gzip = false;
@@ -78,10 +74,13 @@ class JsController extends Controller {
if ($gzip) {
$response->addHeader('Content-Encoding', 'gzip');
}
- $response->cacheFor(86400);
+
+ $ttl = 31536000;
+ $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable');
+
$expires = new \DateTime();
$expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
+ $expires->add(new \DateInterval('PT'.$ttl.'S'));
$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
$response->addHeader('Pragma', 'cache');
return $response;
@@ -92,8 +91,10 @@ class JsController extends Controller {
* @param string $fileName
* @param bool $gzip is set to true if we use the gzip file
* @return ISimpleFile
+ *
+ * @throws NotFoundException
*/
- private function getFile(ISimpleFolder $folder, $fileName, &$gzip) {
+ private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile {
$encoding = $this->request->getHeader('Accept-Encoding');
if (strpos($encoding, 'gzip') !== false) {