- 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.
推薦閱讀
- LabVIEW 2018 虛擬儀器程序設計
- JavaScript:Functional Programming for JavaScript Developers
- 數據結構(Java語言描述)
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- INSTANT Mercurial SCM Essentials How-to
- C++程序設計基礎教程
- 數據結構案例教程(C/C++版)
- Python機器學習算法: 原理、實現與案例
- R數據科學實戰:工具詳解與案例分析
- Vue.js應用測試
- WildFly Cookbook
- After Effects CC技術大全
- 實戰Python網絡爬蟲
- Swift High Performance
- 軟件開發中的決策:權衡與取舍