- 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.
推薦閱讀
- SPSS數據挖掘與案例分析應用實踐
- Android項目開發入門教程
- Kinect for Windows SDK Programming Guide
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- 深入分布式緩存:從原理到實踐
- Swift 4從零到精通iOS開發
- 軟件項目管理實用教程
- Flowable流程引擎實戰
- Unity 2018 Augmented Reality Projects
- Arduino Wearable Projects
- Python Deep Learning
- C語言程序設計教程
- Node.js 6.x Blueprints
- Effective Python:編寫高質量Python代碼的90個有效方法(原書第2版)
- PHP從入門到精通(微視頻精編版)