{"id":20143,"date":"2024-01-05T18:32:09","date_gmt":"2024-01-05T10:32:09","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=20143"},"modified":"2024-01-05T18:32:09","modified_gmt":"2024-01-05T10:32:09","slug":"%e6%9c%89%e4%bc%81%e4%b8%9a%e7%bd%91%e7%ab%99%e6%80%8e%e4%b9%88%e7%94%9f%e6%88%90app%e7%bd%91%e7%ab%99%e5%91%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2024\/20143\/","title":{"rendered":"\u6709\u4f01\u4e1a\u7f51\u7ad9\u600e\u4e48\u751f\u6210app\u7f51\u7ad9\u5462\uff1f"},"content":{"rendered":"<p>\u5f53\u4f60\u62e5\u6709\u4e00\u4e2a\u4f01\u4e1a\u7f51\u7ad9\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u4e00\u4e2aAPP\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\u5e76\u4e14\u589e\u52a0\u54c1\u724c\u4ef7\u503c\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636eWeb\u6280\u672f\u5236\u4f5cAPP\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u79cd\u53eb\u505a&#8221;\u6e10\u8fdb\u5f0f\u7f51\u9875\u5e94\u7528&#8221;\uff08Progressive Web App, \u7b80\u79f0PWA\uff09\u7684\u6280\u672f\u3002<\/p>\n<p>1. \u4ec0\u4e48\u662fPWA\uff1f<\/p>\n<p>PWA\u662f\u4e00\u79cd\u53ef\u4ee5\u8ba9\u4f60\u7684\u7f51\u7ad9\u5177\u5907\u539f\u751fAPP\u7279\u6027\u7684\u6280\u672f\u3002\u5b83\u5177\u6709\u4e00\u4e9b\u663e\u8457\u7684\u4f18\u70b9\uff0c\u4f8b\u5982\u53ef\u79bb\u7ebf\u8bbf\u95ee\u3001\u7c7b\u4f3cAPP\u7684UI\u3001\u81ea\u52a8\u66f4\u65b0\u7b49\u3002\u8fd9\u4e00\u5207\u90fd\u662f\u901a\u8fc7\u4f7f\u7528\u540d\u4e3aService Worker\uff08\u670d\u52a1\u5de5\u4f5c\u8005\uff09\u7684\u6280\u672f\u5b9e\u73b0\u7684\u3002\u4e0e\u4f20\u7edfAPP\u76f8\u6bd4\uff0cPWA\u5177\u6709\u66f4\u5feb\u7684\u52a0\u8f7d\u901f\u5ea6\uff0c\u66f4\u5c11\u7684\u6570\u636e\u6d88\u8017\uff0c\u5e76\u4e14\u4e0d\u9700\u8981\u63d0\u4ea4\u5230\u5e94\u7528\u5546\u5e97\u3002<\/p>\n<p>2. \u600e\u4e48\u628a\u7f51\u7ad9\u8f6c\u6210PWA APP\uff1f<\/p>\n<p>(1) \u5f00\u53d1HTTPS\u8fde\u63a5<\/p>\n<p>\u9996\u5148\u786e\u4fdd\u4f60\u7684\u7f51\u7ad9\u90e8\u7f72\u5728\u652f\u6301HTTPS\u7684\u670d\u52a1\u5668\u4e0a\u3002\u8fd9\u662f\u5fc5\u987b\u7684\u56e0\u4e3aPWA\u4f7f\u7528\u6d89\u53ca\u5230\u7528\u6237\u6570\u636e\u5b89\u5168\u7684\u529f\u80fd\uff0c\u53ea\u6709\u5728HTTPS\u4e0b\u624d\u80fd\u5f00\u542f\u3002<\/p>\n<p>(2) \u521b\u5efaWeb App Manifest<\/p>\n<p>Web App Manifest\u662f\u4e00\u4e2a\u5305\u542b\u7f51\u7ad9\u76f8\u5173\u4fe1\u606f\u7684JSON\u6587\u4ef6\uff0c\u5982\u540d\u79f0\u3001\u56fe\u6807\u3001\u63cf\u8ff0\u3001\u542f\u52a8\u9875\u3001\u5c4f\u5e55\u65b9\u5411\u7b49\u3002\u521b\u5efa\u4e00\u4e2amanifest.json\u6587\u4ef6\u5e76\u5728\u7f51\u9875\u4e2d\u5f15\u7528\u5b83\u3002<\/p>\n<p>\u793a\u4f8b\uff1amanifest.json<\/p>\n<p>&#8220;`json<\/p>\n<p>{<\/p>\n<p>  &#8220;name&#8221;: &#8220;YourAppName&#8221;,<\/p>\n<p>  &#8220;short_name&#8221;: &#8220;AppName&#8221;,<\/p>\n<p>  &#8220;description&#8221;: &#8220;A description of your app&#8221;,<\/p>\n<p>  &#8220;start_url&#8221;: &#8220;\/&#8221;,<\/p>\n<p>  &#8220;display&#8221;: &#8220;standalone&#8221;,<\/p>\n<p>  &#8220;background_color&#8221;: &#8220;#ffffff&#8221;,<\/p>\n<p>  &#8220;theme_color&#8221;: &#8220;#000000&#8221;,<\/p>\n<p>  &#8220;icons&#8221;: [<\/p>\n<p>    {<\/p>\n<p>      &#8220;src&#8221;: &#8220;\/icons\/icon-192&#215;192.png&#8221;,<\/p>\n<p>      &#8220;sizes&#8221;: &#8220;192&#215;192&#8221;,<\/p>\n<p>      &#8220;type&#8221;: &#8220;image\/png&#8221;<\/p>\n<p>    },<\/p>\n<p>    {<\/p>\n<p>      &#8220;src&#8221;: &#8220;\/icons\/icon-256&#215;256.png&#8221;,<\/p>\n<p>      &#8220;sizes<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-01\/06\/14\/11760473760.jpg\" \/><\/figure>\n<\/p>\n<p>&#8220;: &#8220;256&#215;256&#8221;,<\/p>\n<p>      &#8220;type&#8221;: &#8220;image\/png&#8221;<\/p>\n<p>    },<\/p>\n<p>    {<\/p>\n<p>      &#8220;src&#8221;: &#8220;\/icons\/icon-512&#215;512.png&#8221;,<\/p>\n<p>      &#8220;sizes&#8221;: &#8220;512&#215;512&#8221;,<\/p>\n<p>      &#8220;type&#8221;: &#8220;image\/png&#8221;<\/p>\n<p>    }<\/p>\n<p>  ]<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>(3) \u6dfb\u52a0Service Worker<\/p>\n<p>\u521b\u5efa\u4e00\u4e2ajs\u6587\u4ef6\uff08\u4f8b\u5982\uff1asw.js\uff09\uff0c\u8fd9\u662fservice worker\u7684\u6838\u5fc3\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u7f16\u5199\u7f13\u5b58\u7b56\u7565\u3001\u54cd\u5e94\u79bb\u7ebf\u8bf7\u6c42\u3001\u81ea\u52a8\u66f4\u65b0\u7b49\u529f\u80fd\u3002<\/p>\n<p>\u793a\u4f8b\uff1a\u5728\u4e3b\u6587\u4ef6\u4e2d\u6ce8\u518cService Worker\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>if (&#8216;serviceWorker&#8217; in navigator) {<\/p>\n<p>  navigator.serviceWorker.register(&#8216;\/sw.js&#8217;).then(function(registration) {<\/p>\n<p>    console.log(&#8216;Service Worker registered with scope:&#8217;, registration.scope);<\/p>\n<p>  }).catch(function(error) {<\/p>\n<p>    console.log(&#8216;Service Worker registration failed:&#8217;, error);<\/p>\n<p>  });<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>(4) \u914d\u7f6eService Worker<\/p>\n<p>\u5728sw.js\u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u5b9a\u4e49\u7f13\u5b58\u7b56\u7565\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>self.addEventListener(&#8216;install&#8217;, function(event) {<\/p>\n<p>  event.waitUntil(<\/p>\n<p>    caches.open(&#8216;your-cache-name&#8217;).then(function(cache) {<\/p>\n<p>      return cache.addA<a href=\"http:\/\/www.yimenyun.cn\/app-shengcheng-gongju-294.html\">\u5c71\u4e1c\u7f51\u7ad9\u4ee3\u7801\u751f\u6210\u5668app<\/a>ll([<\/p>\n<p>        &#8216;\/&#8217;,<\/p>\n<p>        &#8216;\/index.html&#8217;,<\/p>\n<p>        &#8216;\/css\/main.css&#8217;,<\/p>\n<p>        &#8216;\/js\/main.js&#8217;,<\/p>\n<p>        \/\/ \u66f4\u591a\u9700\u8981\u7f13\u5b58\u7684\u6587\u4ef6<\/p>\n<p>      ]);<\/p>\n<p>    })<\/p>\n<p>  );<\/p>\n<p>});<\/p>\n<p>self.addEventListener(&#8216;fetch&#8217;, function(event) {<\/p>\n<p>  event.respondWith(<\/p>\n<p>    caches.match(event.request).then(function(response) {<\/p>\n<p>      return response || fetch(event.request);<\/p>\n<p>    })<\/p>\n<p> <a href=\"http:\/\/www.yimenyun.cn\/zaixian-shengcheng-app-177.html\">\u5728\u7ebfapp\u751f\u6210\u7684<\/a> );<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u4e4b\u540e\uff0c\u4f60\u7684\u7f51\u7ad9\u5c31\u5177\u5907\u4e86PWA\u7684\u529f\u80fd\u3002\u7528\u6237\u53ef\u4ee5\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u901a\u8fc7\u6d4f\u89c8\u5668\u7684\u201c\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u201d\u529f\u80fd\u5c06\u4f60\u7684\u7f51\u7ad9\u5b89\u88c5\u6210APP\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u867d\u7136PWA\u53ef\u4ee5\u63d0\u4f9b\u7c7b\u4f3cAPP\u7684\u4f53\u9a8c\uff0c\u4f46\u5e76\u4e0d\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u5b8c\u5168\u66ff\u4ee3\u539f\u751fAPP\u3002\u539f\u751fAPP\u5728\u67d0\u4e9b\u6027\u80fd\u548c\u529f\u80fd\u65b9\u9762\u53ef\u80fd\u4ecd\u5177\u6709\u4f18\u52bf\u3002\u56e0\u6b64\uff0c\u4f60\u9700\u8981\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u548c\u9884\u7b97\u6765\u6743\u8861\u8fd9\u4e24\u79cd\u6280\u672f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u62e5\u6709\u4e00\u4e2a\u4f01\u4e1a\u7f51\u7ad9\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u4e00\u4e2aAPP\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\u5e76\u4e14\u589e\u52a0\u54c1\u724c\u4ef7\u503c\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636eWeb\u6280\u672f\u5236\u4f5cAPP\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u79cd\u53eb\u505a\\&#8221;\u6e10\u8fdb\u5f0f\u7f51\u9875\u5e94\u7528\\&#8221;\uff08Progr<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[171,72,76,16162,4623],"class_list":["post-20143","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-171","tag-72","tag-76","tag-app"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/20143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=20143"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/20143\/revisions"}],"predecessor-version":[{"id":20160,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/20143\/revisions\/20160"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=20143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=20143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=20143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}