A cache aware provider for HTTP2 Push within a Laravel application
souhail/laravel-http2-push2 is a Laravel package for a cache aware provider for http2 push within a laravel application.
It currently has 1 GitHub stars and 12 downloads on Packagist (latest version 1.2).
Install it with composer require souhail/laravel-http2-push2.
Discover more Laravel packages by souhail
or browse all Laravel packages to compare alternatives.
Last updated
A cache-aware HTTP2 Server Push implementation, for the Laravel framework
For a comprehensive study of the impacts of HTTP2 Push, check out this article, courtesy of Merj Ltd
HTTP2 Push is hard! This package makes it easy, providing a simple blade directive that informs clients "Hey, I know you've only asked for a HTML document, but I already know you'll need this stylesheet, so just start downloading them now".
Resources are pushed once per cached-lifetime.
i.e, say you have a stylesheet with a cache length set via the Cache-Control header, with an expiry length of 28 days.
The package will initially push the resource, and also set a cookie to track (per resource) whether it has been sent, and therefore cached - after all, there's no need to push a resource that the browser has already cached (Hence the motivation behind this package).
Install the package via composer:
composer require tomkeyte/laravel-http2-push
Publish the configuration (recommended):
php artisan vendor:publish --provider="TomKeyte\LaravelHttp2Push\Http2PushServiceProvider"
IMPORTANT! HTTP2 Push via the Link header must be enabled for your webserver
Instructions for nginx and apache.
Check the http2push.php config file to set default expiry lengths based on your setup. N.B, expiry lengths throughout the package are expressed in days - a value of -1 indicates no cookie should be set, resulting in a push on all requests.
The setup is as following:
cookie_expires_in'cookie_expire_types' => [
'font' => 90,
'script' => 27,
'style' => 24,
'image' => 30,
],
'always' => [
'/js/app.js', # A simple string
[
'src' => '/css/app.css', # Or an array, containing the src & expiry time
'expires' => '90',
],
],
In your blade templates, push the resources:
// use default cookie expiry lengths
@h2push('/css/app.css')
// specify a cookie expiry length of 60 days, for this resource only
@h2push('/js/app.js', 60)
It is recommended you version your resources, so that the package can track whether it needs to re-push them. This package works well with laravel-mix
@h2push( mix('/css/app.css') )
* Every GET request that is routed through the web middleware
composer test
Generate a code coverage report with
composer test-coverage
Requires an applicable code coverage driver, such as xdebug
The MIT License (MIT). Please see License File for more information.