Author: Mohamed Elbahja
Posted on: 2017-10-25
Package: HTTP2 Server Push PHP Class
Read this article to learn how to take advantage of the HTTP2 Server Push feature to improve the performance of PHP sites.
Contents
HTTP2 Performance Advantages
HTTP2 Requirements
How to Install the HTTP2 Server Push PHP Class
How to Use the HTTP2 Server Push PHP Class
Contributing and Support
HTTP2 Performance Advantages
HTTP/2 is a newer version of the HTTP protocol that provides several enhancements for achieving better data access performance like for example using only one TCP connection, as well the server push feature to push all files needed by a page before they are requested like CSS, JavaScript, images etc..
The server push features works by sending special headers to the browser to let it know what are the resources the page needs to be loaded and rendered. Then the browser will load those CSS, JavaScript and Image files in parallel while the current page is still being loaded.
In simple terms, since the HTTP/2 server push can make the server return all the page resources using a single network connection, this feature will make your Web site faster.
In this article I will show you how to use the HTTP2 Server Push PHP Class package to take advantage of the HTTP/2 server push feature.
HTTP2 Requirements
1. Server support for HTTP/2
2. Browser support for HTTP/2
3. HTTPS connections using TLS 1.2: although the specification of HTTP/2 does not require HTTPS support, most browsers require HTTPS to support HTTP/2
If any of these conditions are not met, the requests will fallback to HTTP/1.1.
How to Install the HTTP2 Server Push PHP Class
The HTTP2 Server Push PHP Class can be installed using the Composer tool following instructions in the download page.
Alternatively you can also download the package ZIP archive from the same download page and manually include the class file in your application scripts.
How to Use the HTTP2 Server Push PHP Class
1 |
$pusher = \Melbahja\Http2\Pusher::getInstance(); |
1 |
$pusher->link('/assets/css/style.css'); |
1 |
$pusher->src('/assets/js/myjs.js'); |
1 |
$pusher->img('/images/logo.png'); |
1 2 3 4 |
$pusher->img('/uploads/post.jpg') ->link('/assets/css/bootstrap.css') ->js('/assets/js/jquery.js') ->set(Pusher::LINK, '/assets/css/main.css'); |
Contributing and Support
If you liked this package and would to contribute to its development, you can send your pull requests to the package repository in Github.
if you have any questions or remarks about the package post a comment here below.
Fonte: https://www.phpclasses.org/blog/package/10553/post/1-Benefiting-from-HTTP2-Server-Push-and-other-HTTP-2-Performance-Advantages-in-PHP.html