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

  • Jakarta EE Cookbook
  • Elder Moraes
  • 137字
  • 2021-06-24 16:12:45

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.

主站蜘蛛池模板: 仁寿县| 龙游县| 四川省| 京山县| 建宁县| 赣州市| 固安县| 玛沁县| 斗六市| 江北区| 绍兴县| 崇明县| 谢通门县| 天等县| 高邮市| 台南市| 阿拉善盟| 克什克腾旗| 山东省| 平陆县| 仁化县| 江华| 福州市| 察雅县| 三门县| 柳州市| 囊谦县| 兴化市| 民权县| 开远市| 海安县| 遵义县| 西盟| 正安县| 孟州市| 浠水县| 蓬莱市| 常宁市| 徐闻县| 望谟县| 泽库县|