{"id":172303,"date":"2024-11-07T12:00:19","date_gmt":"2024-11-07T04:00:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/172303\/"},"modified":"2024-11-07T12:00:20","modified_gmt":"2024-11-07T04:00:20","slug":"%e8%ae%93%e4%bd%a0%e6%9b%b4%e8%bc%95%e9%ac%86-%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%9b%b4%e4%bd%b3%e6%96%b9%e6%b3%95-%e5%a6%82%e4%bd%95%e5%9c%a8%e4%b8%bb%e7%b7%9a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/172303\/","title":{"rendered":"\u8b93\u4f60\u66f4\u8f15\u9b06\u2014\u2014\u7372\u53d6\u6578\u64da\u5eab\u7684\u66f4\u4f73\u65b9\u6cd5 (\u5982\u4f55\u5728\u4e3b\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e8%ae%93%e4%bd%a0%e6%9b%b4%e8%bc%95%e9%ac%86-%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%9b%b4%e4%bd%b3%e6%96%b9%e6%b3%95-%e5%a6%82%e4%bd%95%e5%9c%a8%e4%b8%bb%e7%b7%9a-YflCAhFszG\">\u8b93\u4f60\u66f4\u8f15\u9b06\u2014\u2014\u7372\u53d6\u6578\u64da\u5eab\u7684\u66f4\u4f73\u65b9\u6cd5 (\u5982\u4f55\u5728\u4e3b\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\u5eab)<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u5df2\u7d93\u6210\u70ba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7121\u8ad6\u662f\u7db2\u7ad9\u3001\u79fb\u52d5\u61c9\u7528\u9084\u662f\u4f01\u696d\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u90fd\u626e\u6f14\u8457\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u7684\u91cd\u8981\u89d2\u8272\u3002\u7136\u800c\uff0c\u5982\u4f55\u5728\u4e3b\u7dda\u7a0b\u4e2d\u6709\u6548\u5730\u7372\u53d6\u6578\u64da\u5eab\u7684\u6578\u64da\uff0c\u537b\u662f\u4e00\u500b\u503c\u5f97\u6df1\u5165\u63a2\u8a0e\u7684\u8a71\u984c\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87%e4%b8%bb%e7%b7%9a%e7%a8%8b%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%e6%95%b8%e6%93%9a-YflCAhFszG\">\u70ba\u4ec0\u9ebc\u9078\u64c7\u4e3b\u7dda\u7a0b\u7372\u53d6\u6578\u64da\u5eab\u6578\u64da<\/h2>\n<p>\u5728\u8a31\u591a\u61c9\u7528\u4e2d\uff0c\u4e3b\u7dda\u7a0b\u8ca0\u8cac\u8655\u7406\u7528\u6236\u754c\u9762\u548c\u7528\u6236\u4ea4\u4e92\u3002\u5982\u679c\u5728\u4e3b\u7dda\u7a0b\u4e2d\u76f4\u63a5\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u61c9\u7528\u7684\u97ff\u61c9\u8b8a\u6162\uff0c\u751a\u81f3\u51fa\u73fe\u5361\u9813\u7684\u60c5\u6cc1\u3002\u56e0\u6b64\uff0c\u4e86\u89e3\u5982\u4f55\u5728\u4e3b\u7dda\u7a0b\u4e2d\u9ad8\u6548\u7372\u53d6\u6578\u64da\u5eab\u6578\u64da\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%95%b0%e6%ad%a5%e6%93%8d%e4%bd%9c-YflCAhFszG\">\u4f7f\u7528\u7570\u6b65\u64cd\u4f5c<\/h2>\n<p>\u5728\u4e3b\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\u5eab\u6578\u64da\u7684\u6700\u4f73\u65b9\u6cd5\u4e4b\u4e00\u662f\u4f7f\u7528\u7570\u6b65\u64cd\u4f5c\u3002\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u963b\u585e\u4e3b\u7dda\u7a0b\uff0c\u5f9e\u800c\u4fdd\u6301\u61c9\u7528\u7684\u6d41\u66a2\u6027\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 JavaScript \u7684\u4e00\u500b\u7c21\u55ae\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u7570\u6b65\u51fd\u6578\u4f86\u7372\u53d6\u6578\u64da\uff1a<\/p>\n<pre><code>\nasync function fetchData() {\n    try {\n        const response = await fetch('https:\/\/api.example.com\/data');\n        const data = await response.json();\n        console.log(data);\n    } catch (error) {\n        console.error('\u7372\u53d6\u6578\u64da\u6642\u51fa\u932f:', error);\n    }\n}\n\nfetchData();\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u4e86 <code>async\/await<\/code> \u8a9e\u6cd5\u4f86\u9032\u884c\u7570\u6b65\u64cd\u4f5c\uff0c\u9019\u6a23\u53ef\u4ee5\u5728\u4e0d\u963b\u585e\u4e3b\u7dda\u7a0b\u7684\u60c5\u6cc1\u4e0b\u7372\u53d6\u6578\u64da\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-web-workers-YflCAhFszG\">\u4f7f\u7528 Web Workers<\/h2>\n<p>\u53e6\u4e00\u7a2e\u5728\u4e3b\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\u5eab\u6578\u64da\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Web Workers\u3002Web Workers \u5141\u8a31\u4f60\u5728\u80cc\u666f\u7dda\u7a0b\u4e2d\u57f7\u884c JavaScript\uff0c\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u4e3b\u7dda\u7a0b\u7684\u963b\u585e\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\n\/\/ worker.js\nself.onmessage = function(event) {\n    const data = fetchDataFromDatabase(event.data);\n    self.postMessage(data);\n};\n\n\/\/ main.js\nconst worker = new Worker('worker.js');\nworker.onmessage = function(event) {\n    console.log('\u5f9e\u6578\u64da\u5eab\u7372\u53d6\u7684\u6578\u64da:', event.data);\n};\nworker.postMessage('\u8acb\u6c42\u6578\u64da');\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u4e3b\u7dda\u7a0b\u901a\u904e Web Worker \u767c\u9001\u8acb\u6c42\uff0c\u7136\u5f8c\u5728\u80cc\u666f\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\uff0c\u6700\u5f8c\u5c07\u6578\u64da\u8fd4\u56de\u7d66\u4e3b\u7dda\u7a0b\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%b7%a9%e5%ad%98%e6%8a%80%e8%a1%93-YflCAhFszG\">\u4f7f\u7528\u7de9\u5b58\u6280\u8853<\/h2>\n<p>\u70ba\u4e86\u9032\u4e00\u6b65\u63d0\u9ad8\u6578\u64da\u7372\u53d6\u7684\u6548\u7387\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u7de9\u5b58\u6280\u8853\u3002\u901a\u904e\u5c07\u5e38\u7528\u7684\u6578\u64da\u7de9\u5b58\u5728\u5ba2\u6236\u7aef\uff0c\u53ef\u4ee5\u6e1b\u5c11\u5c0d\u6578\u64da\u5eab\u7684\u8acb\u6c42\u6b21\u6578\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7de9\u5b58\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nlet cache = {};\n\nasync function getData(key) {\n    if (cache[key]) {\n        return cache[key];\n    } else {\n        const response = await fetch(`https:\/\/api.example.com\/data\/${key}`);\n        const data = await response.json();\n        cache[key] = data;\n        return data;\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u9996\u5148\u6aa2\u67e5\u7de9\u5b58\u4e2d\u662f\u5426\u5df2\u7d93\u5b58\u5728\u6240\u9700\u7684\u6578\u64da\uff0c\u5982\u679c\u5b58\u5728\u5247\u76f4\u63a5\u8fd4\u56de\uff0c\u5426\u5247\u5f9e\u6578\u64da\u5eab\u7372\u53d6\u4e26\u5b58\u5165\u7de9\u5b58\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-YflCAhFszG\">\u7d50\u8ad6<\/h2>\n<p>\u5728\u4e3b\u7dda\u7a0b\u4e2d\u7372\u53d6\u6578\u64da\u5eab\u6578\u64da\u7684\u904e\u7a0b\u4e2d\uff0c\u4f7f\u7528\u7570\u6b65\u64cd\u4f5c\u3001Web Workers \u548c\u7de9\u5b58\u6280\u8853\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u9019\u4e9b\u65b9\u6cd5\u4e0d\u50c5\u80fd\u5920\u6e1b\u5c11\u4e3b\u7dda\u7a0b\u7684\u8ca0\u64d4\uff0c\u9084\u80fd\u78ba\u4fdd\u61c9\u7528\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u7684\u6d41\u66a2\u6027\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u4f60\u7684\u6578\u64da\u5eab\u64cd\u4f5c\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u4f60\u8f15\u9b06\u7ba1\u7406\u548c\u7372\u53d6\u6578\u64da\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u4f60\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5728\u4e3b\u7dda\u7a0b\u4e2d\u8f15\u9b06\u7372\u53d6\u6578\u64da\u5eab\u7684\u6700\u4f73\u65b9\u6cd5\uff0c\u63d0\u5347\u6548\u7387\uff0c\u7c21\u5316\u6578\u64da\u8655\u7406\u6d41\u7a0b\uff0c\u8b93\u958b\u767c\u66f4\u9806\u66a2\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-172303","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=172303"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172303\/revisions"}],"predecessor-version":[{"id":172304,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172303\/revisions\/172304"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=172303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=172303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=172303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}