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

  • 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.

主站蜘蛛池模板: 青河县| 怀集县| 尼勒克县| 修水县| 南汇区| 高淳县| 珲春市| 环江| 天祝| 措美县| 镇远县| 菏泽市| 台北市| 即墨市| 吉林省| 屏山县| 丹江口市| 大宁县| 简阳市| 邹城市| 黎平县| 策勒县| 蚌埠市| 南丹县| 伽师县| 海兴县| 新宁县| 镇巴县| 武宣县| 阿克| 鄂伦春自治旗| 太谷县| 霍邱县| 象山县| 金门县| 莲花县| 原平市| 股票| 白山市| 东山县| 介休市|