<\/figure>\n<\/p>\n\u5feb\u6377\u5e94\u7528\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u4e0b\u8f7dWeb App Manifest\u6587\u4ef6\u548cService Worker\u6587\u4ef6\uff0c\u5e76\u6839\u636eWeb App Manifest\u6587\u4ef6\u7684\u4fe1\u606f\u521b\u5efa\u4e00\u4e2a\u5e94\u7528\u56fe\u6807\u3002\u7528\u6237\u53ef\u4ee5\u5c06\u8be5\u56fe\u6807\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u4e0a\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u50cf\u539f\u751f\u5e94\u7528\u4e00\u6837\u4f7f\u7528\u5feb\u6377\u5e94\u7528\u4e86\u3002\u5f53\u7528\u6237\u70b9\u51fb\u5feb\u6377\u5e94\u7528\u56fe\u6807\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u542f\u52a8Service Worker\uff0c\u4ece\u7f13\u5b58\u4e2d\u52a0\u8f7d\u5e94\u7528\u8d44\u6e90\uff0c\u5b9e\u73b0\u79bb\u7ebf\u8bbf\u95ee\u3002<\/p>\n
\u4e8c\u3001\u521b\u5efa\u5feb\u6377\u5e94\u7528\u7684\u65b9\u6cd5<\/p>\n
\u521b\u5efa\u5feb\u6377\u5e94\u7528\u7684\u65b9\u6cd5\u5206\u4e3a\u4e24\u6b65\uff1a\u7f16\u5199Web App Manifest\u6587\u4ef6\u548cService Worker\u6587\u4ef6\uff0c\u4ee5\u53ca\u5c06\u5e94\u7528\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u4e0a\u3002<\/p>\n
1. \u7f16\u5199Web App Manifest\u6587\u4ef6\u548cService Worker\u6587\u4ef6<\/p>\n
Web App Manifest\u6587\u4ef6\u662f\u4e00\u4e2aJSON\u6587\u4ef6\uff0c\u5305\u542b\u4e86\u5e94\u7528\u7684\u57fa\u672c\u4fe1\u606f\u3001\u56fe\u6807\u548c\u542f\u52a8URL\u7b49\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2aWeb App Manifest\u6587\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n
“`<\/p>\n
{<\/p>\n
“name”: “My App”,<\/p>\n
“short_name”: “My App”,<\/p>\n
“start_url”: “\/”,<\/p>\n
“display”: “standalone”,<\/p>\n
“icons”: [<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-72×72.png”,<\/p>\n
“sizes”: “72×72”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-96×96.png”,<\/p>\n
“sizes”: “96×96”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-128×128.png”,<\/p>\n
“sizes”: “128×128”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-144×144.png”,<\/p>\n
“sizes”: “144×144”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-152×152.png”,<\/p>\n
“sizes”: “152×152”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-192×192.png”,<\/p>\n
“sizes”: “192×192”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-384×384.png”,<\/p>\n
“sizes”: “384×384”,<\/p>\n
“type”: “image\/png”<\/p>\n
},<\/p>\n
{<\/p>\n
“src”: “\/img\/icons\/icon-512×512.png”,<\/p>\n
“sizes”: “512×512”,<\/p>\n
“type”: “image\/png”<\/p>\n
}<\/p>\n
]<\/p>\n
}<\/p>\n
“`<\/p>\n
Service Worker\u6587\u4ef6\u662f\u4e00\u4e2aJavaScript\u6587\u4ef6\uff0c\u7528\u4e8e\u7f13\u5b58\u548c\u79bb\u7ebf\u8bbf\u95ee\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2aService Worker\u6587\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n
“`<\/p>\n
const cacheName = ‘my-app-cache’;<\/p>\n
self.addEventListener(‘install’, event => {<\/p>\n
event.waitUntil(<\/p>\n
caches.open(cacheName)<\/p>\n
.then(cache => cache.addAll([<\/p>\n
‘\/’,<\/p>\n
‘\/index.html’,<\/p>\n
‘\/css\/style.css’,<\/p>\n
‘\/js\/main.js’<\/p>\n
]))<\/p>\n
);<\/p>\n
});<\/p>\n
self.addEventListener(‘fetch’, event => {<\/p>\n
event.respondWith(<\/p>\n
caches.match(event.request)<\/p>\n
.then(response => response || fetch(event.request))<\/p>\n
);<\/p>\n
});<\/p>\n
“`<\/p>\n
\u5176\u4e2d\uff0cinstall\u4e8b\u4ef6\u7528\u4e8e\u7f13\u5b58\u5e94\u7528\u8d44\u6e90\uff0cfetch\u4e8b\u4ef6\u7528\u4e8e\u4ece\u7f13\u5b58\u4e2d\u52a0\u8f7d\u8d44\u6e90\u3002<\/p>\n
2. \u5c06\u5e94\u7528\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u4e0a<\/p>\n
\u5c06\u5e94\u7528\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u4e0a\u7684\u65b9\u6cd5\u56e0\u6d4f\u89c8\u5668\u800c\u5f02\uff0c\u4e0b\u9762\u4ee5Chrome\u6d4f\u89c8\u5668\u4e3a\u4f8b\uff1a<\/p>\n
1) \u5728Chrome\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u5e94\u7528\u3002<\/p>\n
2) \u70b9\u51fb\u5730\u5740\u680f\u53f3\u4fa7\u7684\u201c\u4e09\u4e2a\u70b9\u201d\u6309\u94ae\uff0c\u9009\u62e9\u201c\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u201d\u3002<\/p>\n
3) \u8f93\u5165\u5e94\u7528\u540d\u79f0\uff0c\u70b9\u51fb\u201c\u6dfb\u52a0\u201d\u3002<\/p>\n
4) \u5e94\u7528\u56fe\u6807\u5c06\u88ab\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u4e0a\u3002<\/p>\n
\u4e09\u3001\u603b\u7ed3<\/p>\n
\u5feb\u6377\u5e94\u7528\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u6280\u672f\u7684\u8f7b\u91cf\u7ea7\u5e94\u7528\uff0c\u53ef\u4ee5\u5728\u6ca1\u6709\u4e0b\u8f7d\u548c\u5b89\u88c5\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u5728\u624b\u673a\u4e3b\u5c4f\u5e55\u4e0a\u4f7f\u7528\u3002\u5feb\u6377\u5e94\u7528\u7684\u5b9e\u73b0\u539f\u7406\u662f\u901a\u8fc7Web App Manifest\u6587\u4ef6\u548cService Worker\u6280\u672f\u5b9e\u73b0\u7684\u3002\u521b\u5efa\u5feb\u6377\u5e94\u7528\u7684\u65b9\u6cd5\u5206\u4e3a\u4e24\u6b65\uff1a\u7f16\u5199Web App Manifest\u6587\u4ef6\u548cService Worker\u6587\u4ef6\uff0c\u4ee5\u53ca\u5c06\u5e94\u7528\u6dfb\u52a0<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5feb\u6377\u5e94\u7528\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u6280\u672f\u7684\u8f7b\u91cf\u7ea7\u5e94\u7528\uff0c\u53ef\u4ee5\u5728\u6ca1\u6709\u4e0b\u8f7d\u548c\u5b89\u88c5\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u5728\u624b\u673a\u4e3b\u5c4f\u5e55\u4e0a\u4f7f\u7528\u3002\u5feb\u6377\u5e94\u7528\u5177\u6709\u5feb\u901f\u3001\u7701\u6d41\u91cf\u3001\u6613\u5206\u53d1\u7b49\u4f18\u70b9\uff0c\u56e0\u6b64\u5728\u79fb\u52a8\u4e92\u8054\u7f51\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5feb\u6377\u5e94\u7528\u7684\u539f\u7406\u548c\u521b<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[16399,27265,12,849,2075],"topic":[],"class_list":["post-30163","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-ghost","tag-urlexe","tag-12","tag-849","tag-2075"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/30163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=30163"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/30163\/revisions"}],"predecessor-version":[{"id":30222,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/30163\/revisions\/30222"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=30163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=30163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=30163"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=30163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}