Enable HTTP/2 server push for CSS and JS resources

This commit is contained in:
Kijin Sung 2016-05-06 22:02:47 +09:00
parent 4290f5110c
commit 942235b6bc
2 changed files with 25 additions and 0 deletions

View file

@ -440,6 +440,18 @@ class FrontEndFileHandler extends Handler
}
}
}
// Enable HTTP/2 server push for JS resources.
if ($finalize && config('view.server_push') && strncmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/2', 6) === 0)
{
foreach ($result as $resource)
{
if ($resource['file'][0] === '/' && $resource['file'][1] !== '/')
{
header(sprintf('Link: <%s>; rel=preload; as=style', $resource['file']), false);
}
}
}
return $result;
}
@ -532,6 +544,18 @@ class FrontEndFileHandler extends Handler
}
}
}
// Enable HTTP/2 server push for JS resources.
if ($finalize && config('view.server_push') && strncmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/2', 6) === 0)
{
foreach ($result as $resource)
{
if ($resource['file'][0] === '/' && $resource['file'][1] !== '/')
{
header(sprintf('Link: <%s>; rel=preload; as=script', $resource['file']), false);
}
}
}
return $result;
}

View file

@ -74,6 +74,7 @@ return array(
'view' => array(
'minify_scripts' => 'common',
'concat_scripts' => 'none',
'server_push' => false,
'use_gzip' => false,
),
'admin' => array(