\u628a\u7f51\u7ad9\u751f\u6210app\u7684\u8f6f\u4ef6<\/a>\u7528\u5e02\u573a\uff0c\u4f9b\u7528\u6237\u4e0b\u8f7d\u3002<\/p>\n2.\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff08PWA\uff09<\/p>\n
PWA\uff08Progressive Web Apps\uff09\u662f\u5c06Web\u5e94\u7528\u4e0e\u539f\u751f\u5e94\u7528\u7279\u70b9\u7ed3\u5408\u7684\u4e00\u79cd\u65b0\u578b\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u5141\u8bb8\u4f60\u4e3a\u73b0\u6709\u7f51\u7ad9\u6dfb\u52a0\u7c7b\u4f3c\u4e8e\u539f\u751f\u5e94\u7528\u7684\u529f\u80fd\uff0c\u800c\u4e0d\u9700\u8981\u521b\u5efa\u65b0\u7684APP\u3002\u8fd9\u4f7f\u5f97\u7f51\u7ad9\u80fd\u591f\u5728\u79bb\u7ebf\u72b6\u6001\u4e0b\u5de5\u4f5c\uff0c\u5e76\u4f7f\u5176\u9002\u5e94\u4e0d\u540c\u7684\u8bbe\u5907\u548c\u7f51\u7edc\u6761\u4ef6\u3002<\/p>\n
\u5982\u4f55\u5c06\u7f51\u7ad9\u5feb\u901f\u751f\u6210PWA\uff1a<\/p>\n
\u6b65\u9aa41\uff1a\u5728\u4f60\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a”manifest.json”\u7684\u6587\u4ef6\u3002\u6b64\u6587\u4ef6\u7528\u4e8e\u5b58\u50a8\u6709\u5173\u7f51\u7ad9\u7684\u5143\u4fe1\u606f\uff0c\u5305\u62ec\u5e94\u7528\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u56fe\u6807\u4ee5\u53caURL\u7b49\u3002<\/p>\n
\u6b65\u9aa42\uff1a\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230manifest.json\u6587\u4ef6\u4e2d\uff0c\u5e76\u586b\u5199\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n
“`json<\/p>\n
{<\/p>\n
“name”: “Your App Name”,<\/p>\n
“short_name”: “AppShortName”,<\/p>\n
“description”: “A description of your app”,<\/p>\n
“start_url”: “\/”,<\/p>\n
“display”: “standalone”,<\/p>\n
“background_color”: “#ffffff”,<\/p>\n
“theme_color”: “#000000”,<\/p>\n
“icons”: [<\/p>\n
{<\/p>\n
“src”: “icon.png”,<\/p>\n
“sizes”: “192×192”,<\/p>\n
“type”: “image\/png”<\/p>\n
}<\/p>\n
]<\/p>\n
}<\/p>\n
“`<\/p>\n
\u6b65\u9aa43\uff1a\u5728\u7f51\u7ad9\u7684HTML\u6587\u4ef6\u4e2d\u7684\u6807\u7b7e\u5185\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u4ee5\u5173\u8054manifest.json\u6587\u4ef6\uff1a<\/p>\n
“`html<\/p>\n<\/p>\n
“`<\/p>\n
\u6b65\u9aa44\uff1a\u521b\u5efaService Worker\u6587\u4ef6\uff08\u4f8b\u5982sw.js\uff09\uff0c\u5e76\u5728\u5176\u4e2d\u5b9a\u4e49\u79bb\u7ebf\u7f13\u5b58\u7b56\u7565\u3001\u6d88\u606f\u63a8\u9001\u7b49\u529f\u80fd\u3002<\/p>\n
\u6b65\u9aa45\uff1a\u5728\u4f60\u7684\u7f51\u7ad9\u4e3b\u8981\u7684JavaScript\u6587\u4ef6\u4e2d\u6ce8\u518cService Worker\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n
“`javascript<\/p>\n
if (‘serviceWorker’ in navigator) {<\/p>\n
navigator.serviceWorker.register(‘\/sw.js’).then(function(registration) {<\/p>\n
console.log(‘Service Worker registered with scope:’, registration.scope);<\/p>\n
}).catch(function(error) {<\/p>\n
console.log(<\/p>\n
<\/figure>\n<\/p>\n‘Service Worker registration failed:’, error);<\/p>\n
});<\/p>\n
}<\/p>\n
“`<\/p>\n
\u6b65\u9aa46\uff1a\u5bf9PWA\u8fdb\u884c\u6d4b\u8bd5\uff0c\u786e\u4fdd\u5176\u529f\u80fd\u6b63\u5e38\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8c37\u6b4c\u6d4f\u89c8\u5668\u7684Lighthouse\u63d2\u4ef6\u6765\u68c0\u67e5PWA\u7279\u6027\u662f\u5426\u6ee1\u8db3\u6807\u51c6\u3002<\/p>\n
\u6b65\u9aa47\uff1a\u5c06\u66f4\u65b0\u540e\u7684\u7f51\u7ad9\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\u3002\u73b0\u5728\uff0c\u7528\u6237\u53ef\u4ee5\u5c06\u4f60\u7684\u7f51\u7ad9\u6dfb\u52a0\u5230\u79fb\u52a8\u8bbe\u5907\u7684\u4e3b\u5c4f\u5e55\uff0c\u5e76\u50cf\u539f\u751fAPP\u4e00\u6837\u4f7f\u7528\u3002<\/p>\n
\u4ee5\u4e0a\u662f\u5c06\u7f51\u7ad9\u5feb\u901f\u751f\u6210\u624b\u673aAPP\u7684\u4e24\u79cd\u65b9\u6cd5\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u548c\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5c06\u7f51\u7ad9\u5feb\u901f\u751f\u6210\u624b\u673aAPP\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5176\u4e2d\u6700\u4e3a\u7b80\u4fbf\u7684\u65b9\u6cd5\u662f\u5c06\u7f51\u7ad9\u8f6c\u6362\u4e3a\u6df7\u5408\u578bAPP\u6216\u8fdb\u884cPWA\uff08\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff09\u7684\u5347\u7ea7\u3002\u8fd9\u4e24\u79cd\u65b9\u6cd5\u5206\u522b\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u5206\u522b\u4e3a\u4f60\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u65b9\u6cd5\u7684\u539f\u7406<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15174,384,797,15173,247],"topic":[],"class_list":["post-8837","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-app","tag-384","tag-797","tag-h5app","tag-247"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=8837"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8837\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=8837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=8837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=8837"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=8837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}