diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/frontend/web/ClientScriptManager.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/frontend/web/ClientScriptManager.php b/app/frontend/web/ClientScriptManager.php index fb8c9fe..a26e0d6 100644 --- a/app/frontend/web/ClientScriptManager.php +++ b/app/frontend/web/ClientScriptManager.php @@ -192,6 +192,7 @@ class ClientScriptManager extends TClientScriptManager { private function _renderLocalScriptFiles(THtmlWriter $writer, array $localFiles) { if ($localFiles) { $assetPath = $this->_compileScriptFiles($localFiles); + $this->_setHTTP2PushHeader($assetPath); $writer->write(TJavascript::renderScriptFile($assetPath)); } } @@ -200,6 +201,7 @@ class ClientScriptManager extends TClientScriptManager { private function _renderExternalScriptFiles(THtmlWriter $writer, array $externalFiles) { if ($externalFiles) { foreach ($externalFiles as $file) { + $this->_setHTTP2PushHeader($file); $this->markScriptFileAsRendered($file); $this->_appendRenderedScripts([$file], $file); } @@ -237,6 +239,9 @@ class ClientScriptManager extends TClientScriptManager { $this->_renderExternalScriptFiles($writer, $externalFiles); } } else { + foreach ($files as $file) { + $this->_setHTTP2PushHeader($file); + } parent::renderScriptFiles($writer, $files); } } @@ -425,6 +430,7 @@ class ClientScriptManager extends TClientScriptManager { } foreach ($fileTypes as $type => $files) { $assetPath = $this->_compileSheetFiles($files); + $this->_setHTTP2PushHeader($assetPath); $this->_renderSheetFileTag($writer, $assetPath, $type); } } @@ -435,6 +441,7 @@ class ClientScriptManager extends TClientScriptManager { if ($externalFiles) { foreach ($externalFiles as $file) { $this->_appendRenderedSheets([$file], $file[0]); + $this->_setHTTP2PushHeader($file[0]); $this->_renderSheetFileTag($writer, $file[0], $file[1] ?: 'all'); } } @@ -474,6 +481,9 @@ class ClientScriptManager extends TClientScriptManager { $this->_renderExternalSheetFiles($writer, $externalFiles); } } else { + foreach ($this->getStyleSheetUrls() as $file) { + $this->_setHTTP2PushHeader($file); + } parent::renderStyleSheetFiles($writer); } } @@ -567,6 +577,16 @@ class ClientScriptManager extends TClientScriptManager { return $this->registerStyleSheetFile($key, $file, $media ?: 'all'); } + private $_pushHeaders = []; + + // Set Link: header for HTTP2 Push + private function _setHTTP2PushHeader($file) { + if (!in_array($file, $this->_pushHeaders)) { + $this->_pushHeaders[] = $file; + $this->getResponse()->appendHeader('Link: "<' . $file . '>; rel=preload"', FALSE); + } + } + } ?> |