{"id":31409,"date":"2023-05-08T06:09:39","date_gmt":"2023-05-07T22:09:39","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=31409"},"modified":"2023-05-08T06:09:39","modified_gmt":"2023-05-07T22:09:39","slug":"http2-node-js","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/http2-node-js.html","title":{"rendered":"\u4f7f\u7528 HTTP\/2 \u52a0\u901f Node.js \u5e94\u7528"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6211\u4eec\u60f3\u8ba9\u73b0\u4eca\u4f7f\u7528 Node.js \u6784\u5efa\u7684\u7f51\u7ad9\u80fd\u591f\u66f4\u52a0\u8f7b\u677e\u7684\u83b7\u5f97\u6027\u80fd\u63d0\u5347\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5f00\u53d1\u4e86 netjet \u4e2d\u95f4\u4ef6\uff0c\u5b83\u53ef\u4ee5\u89e3\u6790\u5e94\u7528\u751f\u6210\u7684 HTML \u5e76\u81ea\u52a8\u6dfb\u52a0 Link \u5934\u90e8\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5f53\u5728\u4e00\u4e2a\u793a\u4f8b\u7684 Express \u5e94\u7528\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u8f93\u51fa\u591a\u4e86\u5982\u4e0b HTTP \u5934\uff1a
\n\"\u4f7f\u7528
\n\u672c\u6587\u662f\u4f7f\u7528 Ghost\uff08\u4e00\u4e2a\u535a\u5ba2\u53d1\u5e03\u5e73\u53f0\uff09\u8fdb\u884c\u53d1\u5e03\u7684\uff0c\u56e0\u6b64\u5982\u679c\u4f60\u7684\u6d4f\u89c8\u5668\u652f\u6301 HTTP\/2\uff0c\u4f60\u5df2\u7ecf\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u4eab\u53d7\u4e86\u670d\u52a1\u7aef\u63a8\u9001\u6280\u672f\u5e26\u6765\u7684\u597d\u5904\u4e86\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8fdb\u884c\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e\u3002netjet \u4f7f\u7528\u4e86\u5e26\u6709\u5b9a\u5236\u63d2\u4ef6\u7684 PostHTML \u6765\u89e3\u6790 HTML\u3002\u76ee\u524d\uff0cnetjet \u7528\u5b83\u6765\u67e5\u627e\u56fe\u7247\u3001\u811a\u672c\u548c\u5916\u90e8 CSS \u6837\u5f0f\u8868\u3002\u4f60\u4e5f\u53ef\u4ee5\u7528\u5176\u5b83\u7684\u6280\u672f\u6765\u5b9e\u73b0\u8fd9\u4e2a\u3002\u5728\u54cd\u5e94\u8fc7\u7a0b\u4e2d\u589e\u52a0 HTML \u89e3\u6790\u5668\u6709\u4e2a\u660e\u663e\u7684\u7f3a\u70b9\uff1a\u8fd9\u5c06\u589e\u52a0\u9875\u9762\u52a0\u8f7d\u7684\u5ef6\u65f6\uff08\u5230\u52a0\u8f7d\u7b2c\u4e00\u4e2a\u5b57\u8282\u6240\u82b1\u7684\u65f6\u95f4)\u3002\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6240\u65b0\u589e\u7684\u5ef6\u65f6\u88ab\u5e94\u7528\u91cc\u7684\u5176\u4ed6\u8017\u65f6\u63a9\u76d6\u6389\u4e86\uff0c\u6bd4\u5982\u6570\u636e\u5e93\u8bbf\u95ee\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cnetjet \u5305\u542b\u4e86\u4e00\u4e2a\u53ef\u8c03\u8282\u7684 LRU \u7f13\u5b58\uff0c\u8be5\u7f13\u5b58\u4ee5 HTTP \u7684 ETag \u5934\u90e8\u4f5c\u4e3a\u7d22\u5f15\uff0c\u8fd9\u4f7f\u5f97 netjet \u53ef\u4ee5\u975e\u5e38\u5feb\u7684\u4e3a\u5df2\u7ecf\u89e3\u6790\u8fc7\u7684\u9875\u9762\u63d2\u5165 Link \u5934\u90e8\u3002
\n\u4e0d\u8fc7\uff0c\u5982\u679c\u6211\u4eec\u73b0\u5728\u4ece\u5934\u8bbe\u8ba1\u4e00\u6b3e\u5168\u65b0\u7684\u5e94\u7528\uff0c\u6211\u4eec\u5c31\u5e94\u8be5\u8003\u8651\u628a\u9875\u9762\u5185\u5bb9\u548c\u9875\u9762\u4e2d\u7684\u5143\u6570\u636e\u5206\u5f00\u5b58\u653e\uff0c\u4ece\u800c\u6574\u4f53\u5730\u51cf\u5c11 HTML \u89e3\u6790\u548c\u5176\u5b83\u53ef\u80fd\u589e\u52a0\u7684\u5ef6\u65f6\u4e86\u3002
\n\u4efb\u610f\u7684 Node.js HTML \u6846\u67b6\uff0c\u53ea\u8981\u5b83\u652f\u6301\u7c7b\u4f3c Express \u8fd9\u6837\u7684\u4e2d\u95f4\u4ef6\uff0cnetjet \u90fd\u662f\u80fd\u591f\u517c\u5bb9\u7684\u3002\u53ea\u8981\u628a netjet \u50cf\u4e0b\u9762\u8fd9\u6837\u52a0\u5230\u4e2d\u95f4\u4ef6\u52a0\u8f7d\u94fe\u91cc\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n

var express = require('express');\r\nvar netjet = require('netjet');\r\nvar root = '\/path\/to\/static\/folder';\r\nexpress()\r\n  .use(netjet({\r\n    cache: {\r\n      max: 100\r\n    }\r\n  }))\r\n  .use(express.static(root))\r\n  .listen(1337);\r\n<\/pre>\n

\u7a0d\u5fae\u52a0\u70b9\u4ee3\u7801\uff0cnetjet \u4e5f\u53ef\u4ee5\u6446\u8131 HTML \u6846\u67b6\uff0c\u72ec\u7acb\u5de5\u4f5c\uff1a<\/p>\n

var http = require('http');\r\nvar netjet = require('netjet');\r\n\r\nvar port = 1337;\r\nvar hostname = 'localhost';\r\nvar preload = netjet({\r\n  cache: {\r\n    max: 100\r\n  }\r\n});\r\n\r\nvar server = http.createServer(function (req, res) {\r\n  preload(req, res, function () {\r\n      res.statusCode = 200;\r\n      res.setHeader('Content-Type', 'text\/html');\r\n      res.end('<!doctype html><h1>Hello World<\/h1>');\r\n  });\r\n});\r\n\r\nserver.listen(port, hostname, function () {\r\n  console.log('Server running at http:\/\/' + hostname + ':' + port+ '\/');\r\n});\r\n<\/pre>\n

netjet \u6587\u6863\u91cc\u6709\u66f4\u591a\u9009\u9879\u7684\u4fe1\u606f\u3002<\/p>\n

\u67e5\u770b\u63a8\u9001\u4e86\u4ec0\u4e48\u6570\u636e<\/strong><\/span><\/div>\n

\"\u4f7f\u7528
\n\u8bbf\u95ee\u672c\u6587<\/a>\u65f6\uff0c\u901a\u8fc7 Chrome \u7684\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u7684\u9a8c\u8bc1\u7f51\u7ad9\u662f\u5426\u6b63\u5728\u4f7f\u7528\u670d\u52a1\u5668\u63a8\u9001\u6280\u672f\uff08LCTT \u8bd1\u6ce8\uff1a Chrome \u7248\u672c\u81f3\u5c11\u4e3a 53\uff09\u3002\u5728\u201cNetwork\u201d\u9009\u9879\u5361\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6709\u4e9b\u8d44\u6e90\u7684\u201cInitiator\u201d\u8fd9\u4e00\u5217\u4e2d\u5305\u542b\u4e86Push<\/span>\u5b57\u6837\uff0c\u8fd9\u4e9b\u8d44\u6e90\u5c31\u662f\u670d\u52a1\u5668\u7aef\u63a8\u9001\u7684\u3002
\n\u4e0d\u8fc7\uff0c\u76ee\u524d Firefox \u7684\u5f00\u53d1\u8005\u5de5\u5177\u8fd8\u4e0d\u80fd\u76f4\u89c2\u7684\u5c55\u793a\u88ab\u63a8\u9001\u7684\u8d44\u6e90\u3002\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9875\u9762\u54cd\u5e94\u5934\u90e8\u91cc\u7684cf-h2-pushed<\/span>\u5934\u90e8\u770b\u5230\u4e00\u4e2a\u5217\u8868\uff0c\u8fd9\u4e2a\u5217\u8868\u5305\u542b\u4e86\u672c\u9875\u9762\u4e3b\u52a8\u63a8\u9001\u7ed9\u6d4f\u89c8\u5668\u7684\u8d44\u6e90\u3002
\n\u5e0c\u671b\u5927\u5bb6\u80fd\u591f\u8e0a\u8dc3\u4e3a netjet \u6dfb\u7816\u52a0\u74e6\uff0c\u6211\u4e5f\u4e50\u4e8e\u770b\u5230\u6709\u4eba\u6b63\u5728\u4f7f\u7528 netjet\u3002<\/p>\n

Ghost \u548c\u670d\u52a1\u7aef\u63a8\u9001\u6280\u672f<\/strong><\/span><\/div>\n

Ghost \u771f\u662f\u5305\u7f57\u4e07\u8c61\u3002\u5728 Ghost \u56e2\u961f\u7684\u5e2e\u52a9\u4e0b\uff0c\u6211\u628a netjet \u4e5f\u96c6\u6210\u5230\u91cc\u9762\u4e86\uff0c\u800c\u4e14\u4f5c\u4e3a\u6d4b\u8bd5\u7248\u5185\u5bb9\u53ef\u4ee5\u5728 Ghost \u7684 0.8.0 \u7248\u672c\u4e2d\u7528\u4e0a\u5b83\u3002<\/p>\n

\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528 Ghost\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 config.js\u3001\u5e76\u5728production<\/span>\u914d\u7f6e\u5757\u4e2d\u589e\u52a0 preloadHeaders<\/span> \u9009\u9879\u6765\u542f\u7528\u670d\u52a1\u7aef\u63a8\u9001\u3002<\/p>\n

production: {\r\n  url: 'https:\/\/my-ghost-blog.com',\r\n  preloadHeaders: 100,\r\n  \/\/ ...\r\n}\r\n<\/pre>\n

Ghost \u5df2\u7ecf\u4e3a\u5176\u7528\u6237\u6574\u7406\u4e86\u4e00\u7bc7\u652f\u6301\u6587\u6863\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/span><\/div>\n

\u4f7f\u7528 netjet\uff0c\u4f60\u7684 Node.js \u5e94\u7528\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6d4f\u89c8\u5668\u9884\u52a0\u8f7d\u6280\u672f\u3002\u5e76\u4e14 CloudFlare \u5df2\u7ecf\u4f7f\u7528\u5b83\u5728\u63d0\u4f9b\u4e86 HTTP\/2 \u670d\u52a1\u7aef\u63a8\u9001\u4e86\u3002<\/p>\n


\n

via: https:\/\/blog.cloudflare.com\/accelerating-node-js-applications-with-http-2-server-push\/<\/a><\/p>\n

\u4f5c\u8005\uff1aTerin Stock<\/a> \u8bd1\u8005\uff1aechoma<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-7770-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/http2-node-js.html<\/a>\u7f16\u8f91\u5458\uff1a\u5218\u5cf0\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u6211\u4eec\u60f3\u8ba9\u73b0\u4eca\u4f7f\u7528 Node.js \u6784\u5efa\u7684\u7f51\u7ad9\u80fd\u591f\u66f4\u52a0\u8f7b\u677e\u7684\u83b7\u5f97\u6027\u80fd\u63d0\u5347\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5f00\u53d1\u4e86 netjet \u4e2d\u95f4\u4ef6\uff0c\u5b83\u53ef\u4ee5\u89e3\u6790\u5e94\u7528\u751f\u6210\u7684 HTML \u5e76\u81ea\u52a8\u6dfb\u52a0 Link \u5934\u90e8\u3002<\/p>\n","protected":false},"author":116,"featured_media":30136,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-31409","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/31409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/116"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=31409"}],"version-history":[{"count":14,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/31409\/revisions"}],"predecessor-version":[{"id":271670,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/31409\/revisions\/271670"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/30136"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=31409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=31409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=31409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}