PHP code example of lenorix / laravel-early-hints
1. Go to this page and download the library: Download lenorix/laravel-early-hints library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lenorix / laravel-early-hints example snippets
use Lenorix\LaravelEarlyHints\Facades\EarlyHints;
EarlyHints::addLinkHeader($response, 'https://one.example.com');
EarlyHints::addLinkHeader($response, 'https://fonts.example.com/font.woff2', rel: 'preload', as: 'font', crossorigin: 'anonymous', type: 'font/woff2', fetchpriority: 'high');
use Lenorix\LaravelEarlyHints\Facades\EarlyHints;
EarlyHints::addLinkHeaders($response, [
'https://one.example.com',
'https://two.example.com',
]);
use Lenorix\LaravelEarlyHints\Facades\EarlyHints;
use Symfony\Component\HttpFoundation\StreamedResponse;
public function show()
{
$response = response()->streamJson([
'title' => 'A blog post',
'cover_image' => 'https://cdn.example.com/cover.jpg',
'gallery' => [
'https://cdn.example.com/img1.jpg',
'https://cdn.example.com/img2.jpg',
],
]);
EarlyHints::addLinkHeaders($response, [
'https://cdn.example.com/cover.jpg',
'https://cdn.example.com/img1.jpg',
'https://cdn.example.com/img2.jpg',
], rel: 'preload', as: 'image');
return $response;
}
Route::get('/dashboard', DashboardController::class)->middleware('early-hints');
return [
'styles_and_scripts' => true,
'images' => true,
'json_pagination' => true,
'images_limit' => 20,
'fonts' => true,
'max_header_bytes' => 4096,
];
bash
php artisan vendor:publish --tag="laravel-early-hints-config"