官术网_书友最值得收藏!

How it works...

A web application running under HTTP/1.0 sends a request to the server when it finds references for an image file, CSS file, and any other resources needed to render a web page.

With HTTP/2.0, you still can do this, but now, you can do this a lot better the server can now push the resources beforehand, avoiding unnecessary new requests, decreasing the server load, and improving performance.

In this recipe, our resources are represented by the following code:

   meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
link rel="stylesheet" type="text/css" href="resources/style.css">
script src="resources/functions.js"></script>

The push happens at this part of our filter:

   HttpServletRequest httpReq = (HttpServletRequest)request;
PushBuilder builder = httpReq.newPushBuilder();

if (builder != null){
builder
.path("resources/javaee-logo.png")
.path("resources/style.css")
.path("resources/functions.js")
.push();
System.out.println("Resources pushed");
}

So, when the browser needs those resources to render the web page, they are already available.

主站蜘蛛池模板: 玉山县| 青阳县| 綦江县| 英德市| 巴青县| 汉中市| 临洮县| 阳东县| 濮阳县| 泰州市| 清河县| 吉木萨尔县| 杭锦后旗| 晋州市| 海晏县| 获嘉县| 开鲁县| 普安县| 永新县| 车险| 和政县| 青岛市| 象州县| 高邑县| 怀仁县| 桃江县| 巴楚县| 双江| 宾川县| 斗六市| 方正县| 开封县| 罗甸县| 观塘区| 额尔古纳市| 潢川县| 山丹县| 湖州市| 惠水县| 遵义县| 湟中县|