PHP Classes


Recommend this page to a friend!
  Classes of Mohamed Elbahja   HTTP2 Server Push PHP Class   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: HTTP2 Server Push PHP Class
Push Web resources using HTTP 2 requests
Author: By
Last change: fix composer command
Date: 6 years ago
Size: 1,745 bytes


Class file image Download


PHP Http2 Server Pusher

About Http2 Server Push :

> HTTP/2 Push allows a web server to send resources to a web browser before the browser gets to request them. It is, for the most part, a performance technique that can help some websites load faster. - wikipedia

http2 image by cloudflare

Installation :

using composer: `composer require melbahja/http2-pusher`

Usage :

get the instance:

require 'vendore/autoload.php';

use Melbahja\Http2\Pusher;

$pusher = Pusher::getInstance();


// set css file

// set css and image and src
	-set(Pusher::IMG, '/assets/img/logo2.png');

// set link with options
$pusher->link('', [
	'as' => false,
	'rel' => 'preconnect' 

// rel by default is preload
// as by default is the link type 

// push header

Public methods :

Pusher::getInstance(): PusherInterface

Pusher::link(string $link, array $opts = []): PusherInterface

Pusher::src(string $link, array $opts = []): PusherInterface

Pusher::img(string $link, array $opts = []): PusherInterface

Pusher::set(string $type, string $link, array $opts = []): PusherInterface

Pusher::getHeader(string $type = null): string

Pusher::push(string $type = null): void

Pusher::public function toHeader(string $type, array $urls): null|string

License :

MIT Copyright (c) 2017 Mohamed Elbahja