- 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.
推薦閱讀
- 新編Visual Basic程序設計上機實驗教程
- 程序員修煉之道:程序設計入門30講
- Deploying Node.js
- Microsoft Application Virtualization Cookbook
- Learning RxJava
- Developing Middleware in Java EE 8
- Rake Task Management Essentials
- Mastering Kotlin
- Getting Started with SQL Server 2012 Cube Development
- ASP.NET 3.5程序設計與項目實踐
- Java Fundamentals
- Android移動開發案例教程:基于Android Studio開發環境
- 代碼閱讀
- H5頁面設計與制作(全彩慕課版·第2版)
- Learning Redux