# Laravel HTTP2 Push

GitHub

# Introduction

If you use HTTP/2 instead of HTTP/1.1, you will gain a nice speed boost when it comes to the load time of your website.
But HTTP/2 also give you features like Server Push which will reduce your load time even further by opening less TCP Conections to the server.
When the client requests the initial document, you may specify additional resources which should be pushed to the client over the same connection.
These resources might be your CSS, your JS or even images, like the first image of your slider module.

This package allows you to easily add the resource to the Link header of the inital document. In a global config file or even on the fly in your blade templates.

# Installation

Via composer.

composer require mrcrmn/laravel-http2-push

# For Laravel < 5.5

If you are not using Laravel's auto-discovery feature, you need to add the ServiceProvider to your providers array in your config/app.php file.

'providers' => [
    /*
     * Package Service Providers...
     */
    mrcrmn\Http2Push\Http2PushServiceProvider::class,
]

To publish the configuration, run the following command.

php artisan vendor:publish --provider="mrcrmn\Http2Push\Http2PushServiceProvider"

# Usage

Navigate to the config/http2push.php file. Under preload you can specify the resources which should be pushed on every request. You probably want to add your main CSS and JS files to this array.

Alternatively, you can add files to push directly in your blade templates on the fly by using the @preload directive like this:

<link href="@preload(mix('css/app.css'))" rel="stylesheet">