display: standalone
独立应用模式,隐藏浏览器地址栏{
"name": "AMS",
"short_name": "AMS",
"start_url": "/",
"theme_color": "#ede5e0",
"background_color": "#fff",
"description": "描述信息",
"display": "standalone",
"lang": "cn",
"orientation": "portrait",
"icons": [
{
"src": "manifest-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "manifest-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "manifest-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "manifest-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "manifest-48x48.png",
"sizes": "48x48",
"type": "image/png"
},
{
"src": "manifest-36x36.png",
"sizes": "36x36",
"type": "image/png"
}
]
}
icons.
使用 image/png ,即时你的图片是jpg格式icons.
至少存在大于等于144*144的尺寸icons.
必须长宽相等
可设置ios端PWA状态栏的颜色,等价于manifest.json中的theme_color
可设置ios端PWA图标图片,等价于manifest.json中144尺寸的iconsstart_url
与当前路由一致时才会触发manifest.json
配置文件,且该配置文件必须包含name、short_name、start_url、iconsService Worker
HTTPS
或 localhost
服务const { InjectManifest } = require('workbox-webpack-plugin')
引入插件new InjectManifest({
swSrc: './sw.js',
swDest: 'sw.js',
importWorkboxFrom: 'disabled', // 关闭自动注入workbox-sw.js
})
importScripts('https://yourdomain.com/workbox-v4.3.1/workbox-sw.js')
引入workbox入口文件workbox.setConfig({
debug: false,
modulePathPrefix: 'https://yourdomain.com/workbox-v4.3.1'
})
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
workbox.strategies.CacheFirst
,网络优先:workbox.strategies.NetworkFirst
,仅使用缓存:workbox.strategies.CacheOnly
,仅使用网络:workbox.strategies.NetworkOnly
,先缓存后网络:workbox.strategies.StaleWhileRevalidate
var cacheFirstOptions = {
requestWillFetch: function(_ref2) {
var request = _ref2.request
request = new Request(request.url)
return request
},
cachedResponseWillBeUsed: function(e) {
if (e.cachedResponse && e.cachedResponse.type === 'opaque') {
caches.delete(e.cacheName)
return null
}
return e.cachedResponse
}
}
workbox.routing.registerRoute(
new RegExp(eval('/^https?:\/\/' + location.host + '(.*).(png|gif|jpg|webp)$/')),
workbox.strategies.cacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxAgeSeconds: 365 * 24 * 60 * 60,
maxEntries: 300 // 缓存条数(FIFO)
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200] // 可被缓存的状态码
}),
cacheFirstOptions,
]
})
)
[1] Google Developers
[2] 深入浅出 PWA
[3] 微博Web App