PHPackages                             justbetter/laravel-http3earlyhints - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. justbetter/laravel-http3earlyhints

ActiveLibrary[HTTP &amp; Networking](/categories/http)

justbetter/laravel-http3earlyhints
==================================

A HTTP3 Early Hints Middleware for Laravel

1.5.3(5d ago)1977.0k↓51.4%21MITPHPPHP ^8.0CI passing

Since May 23Pushed 5d ago4 watchersCompare

[ Source](https://github.com/justbetter/laravel-http3earlyhints)[ Packagist](https://packagist.org/packages/justbetter/laravel-http3earlyhints)[ Docs](https://github.com/justbetter/laravel-http3earlyhints)[ RSS](/packages/justbetter-laravel-http3earlyhints/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (34)Versions (20)Used By (1)

Early Hints Middleware for Laravel
==================================

[](#early-hints-middleware-for-laravel)

Early Hints is a HTTP/3 concept which allows the server to send preconnect and preload headers while it's still preparing a response. This allows the broser to start loading these resources before the server has finished building and sending a response [See](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103).

This package aims to provide the *easiest* experience for adding Early Hints to your responses. Simply route your requests through the `AddHttp3EarlyHints` middleware and it will automatically create and attach the `Link` headers necessary to implement Early Hints for your CSS, JS and Image assets.

Installation
------------

[](#installation)

You can install the package via composer:

```
$ composer require justbetter/laravel-http3earlyhints
```

Next you must add the `\JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints`-middleware to the kernel. Adding it to the web group is recommeneded as API's do not have assets to push.

### Laravel &lt;11

[](#laravel-11)

```
// app/Http/Kernel.php

...
protected $middlewareGroups = [
    'web' => [
        ...
        \JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class,
        ...
    ],
    ...
];
```

### Laravel &gt;=11

[](#laravel-11-1)

```
// bootstrap/app.php

...
->withMiddleware(function (Middleware $middleware) {
    ...
    $middleware->appendToGroup('web', [
        \JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class,
    ]);
    // Or
    // $middleware->append(\JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class);
    ...
})
...
```

Publish config
--------------

[](#publish-config)

```
php artisan vendor:publish --provider="JustBetter\Http3EarlyHints\ServiceProvider"
```

**Note:** `send_103` defaults to `false`, this is because it isn't actually supported widely yet. Currently only [FrankenPHP supports Early Hints natively](https://frankenphp.dev/docs/early-hints/). default behaviour is adding the link headers to the 200 response which e.g. [Cloudflare turns into early hints](https://developers.cloudflare.com/cache/advanced-configuration/early-hints/#generate-early-hints).

Usage
-----

[](#usage)

When you route a request through the `AddHttp3EarlyHints` middleware, the response is scanned for any `link`, `script` or `img` tags that could benefit from being loaded using Early Hints. These assets will be added to the `Link` header before sending the response to the client. Easy!

**Note:** To push an image asset, it must have one of the following extensions: `bmp`, `gif`, `jpg`, `jpeg`, `png`, `svg`, `tiff` or `webp` and not have `loading="lazy"`

### Advanced usage

[](#advanced-usage)

If the automatic detection isn't enough for you, you can listen for the `GenerateEarlyHints` event, and manually add/remove/change new links.

#### Detailed default behaviour

[](#detailed-default-behaviour)

The information on [usage](#usage) is simplified, there are many checks done to make sure we don't preload the wrong things.

Early hints only support rel=preconnect and rel=preload [source](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103#browser_compatibility)

We automatically transform any rel that is not `preconnect` or `preload` into `preload`, so your `` will get preloaded with early hints. And get more detailed information once your server starts sending it's response.

##### Link

[](#link)

Any link elements which do **not** have rel=

- icon
- canonical
- manifest
- alternative

##### Script

[](#script)

Script tags will automatically get preloaded **if** it does not have an `async` or `defer` attribute attached to it.

##### Img

[](#img)

Img tags will automatically get preloaded when it does not have `loading="lazy"` and it does not exist within a picture tag.

If it is within a picture tag we may be dealing with mutliple `srcset`s or `type`s, and thus cannot determine which file the browser will need. So we will not preload these images.

##### Object

[](#object)

If your html object tag contains `data=""` it will preload it.

##### Nonce

[](#nonce)

While the early hints module does support sending [nonce](https://laravel.com/docs/11.x/vite#content-security-policy-csp-nonce) across as well, we recommend against it. And use [integrity](https://laravel.com/docs/11.x/vite#subresource-integrity-sri) instead.

Without hardcoding the nonce [Vite::useCspNonce($nonce);](https://laravel.com/docs/11.x/vite#content-security-policy-csp-nonce:~:text=Vite%3A%3AuseCspNonce(%24nonce)%3B)sending this in early hints will be useless as each request will send early hints with a stale nonce.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance99

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~120 days

Total

17

Last Release

5d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d00b3f55cd4ae8b8cfb001a644ed6c7a1127a956c24375bcfe16ce12bd89bed?d=identicon)[justbetter](/maintainers/justbetter)

---

Top Contributors

[![indykoning](https://avatars.githubusercontent.com/u/15870933?v=4)](https://github.com/indykoning "indykoning (20 commits)")[![Rodeveer](https://avatars.githubusercontent.com/u/8512170?v=4)](https://github.com/Rodeveer "Rodeveer (1 commits)")[![royduin](https://avatars.githubusercontent.com/u/1703233?v=4)](https://github.com/royduin "royduin (1 commits)")

---

Tags

laravelhttp3serverpushlaravel-http3earlyhintsearly hints

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/justbetter-laravel-http3earlyhints/health.svg)

```
[![Health](https://phpackages.com/badges/justbetter-laravel-http3earlyhints/health.svg)](https://phpackages.com/packages/justbetter-laravel-http3earlyhints)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[spatie/crawler

Crawl all internal links found on a website

2.8k18.5M67](/packages/spatie-crawler)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59463.6k](/packages/lomkit-laravel-rest-api)[jacobbennett/laravel-http2serverpush

A HTTP2 Server Push Middleware for Laravel 5

295110.9k](/packages/jacobbennett-laravel-http2serverpush)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
