How it works...

The image loaded in this recipe was shared in 25 pieces. When there is no HTTP/2.0 available, the server will wait for 25 requests made by img src (from HTML) and then reply to each one of them with the proper image.

With HTTP/2.0, the server can push them all beforehand. The magic is done here:

   PushBuilder pb = request.newPushBuilder();
if (pb != null) {
for(int row=0; row < 5; row++){
for(int col=0; col < 8; col++){
pb.path("image/keyboard_buttons/keyboard_buttons-"
+ row + "-" + col + ".jpeg")
.addHeader("content-type", "image/jpeg")
.push();
}
}
}

To check whether your images are loaded using Server Push or not, open the developer console of your browser, go to network monitoring, and then load the page. You should see information about who sent each image to the browser. If there is something like Push or ServerPush, you are using it!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.21.5