Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
郭成尧
7 years ago
Commit
9453eb0e1cc0c7f31934722976f4fb3e11febe93
1 parent
f42f748e
no-image-handle
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
public/js/pwa/sw.js
public/js/pwa/sw.js
View file @
9453eb0
/* eslint-env worker */
/* global FetchEvent */
import
'whatwg-fetch'
;
import
WorkboxSW
from
'workbox-sw'
;
...
...
@@ -7,8 +6,9 @@ import parseQs from 'yoho-qs/parse';
const
config
=
{
customCacheUrl
:
[
/^https:
\/\/(
.*
)
cdn
\.
yoho
\.
cn/i
,
/^https:
\/\/(
.*
)
static
\.
yhbimg
\.
com/i
/^https:
\/\/(
.*
)
cdn
\.
yoho
\.
cn/i
// /^https:\/\/(.*)static\.yhbimg\.com/i
],
precachePage
:
[
'/offline.html'
...
...
@@ -80,27 +80,27 @@ workboxSW.router.registerRoute(/.*/, args => {
* webp 处理
* 匹配非 webp 的 cdn 图片资源,缓存其 webp 格式
*/
workboxSW
.
router
.
registerRoute
(
args
=>
{
let
useWebp
=
false
;
let
supportWebp
=
/image
\/
webp/i
.
test
(
args
.
event
.
request
.
headers
.
get
(
'Accept'
));
// workboxSW.router.registerRoute(args => {
// let useWebp = false;
// let supportWebp = /image\/webp/i.test(args.event.request.headers.get('Accept'));
if
(
!
supportWebp
)
{
return
useWebp
;
}
// if (!supportWebp) {
// return useWebp;
// }
if
(
/^https:
\/\/(
.*
)
static
\.
yhbimg
\.
com
(
.*
)(
png|jpg|jpeg
)\?(
imageView|imageMogr
)(
.*
)
/
.
test
(
args
.
url
.
href
)
&&
/^
(?!
.*format
\/)
.*/
.
test
(
args
.
url
.
href
))
{
useWebp
=
true
;
}
// if (/^https:\/\/(.*)static\.yhbimg\.com(.*)(png|jpg|jpeg)\?(imageView|imageMogr)(.*)/.test(args.url.href) &&
// /^(?!.*format\/).*/.test(args.url.href)) {
// useWebp = true;
// }
return
useWebp
;
},
args
=>
{
// 重新构造 fetch 请求
args
.
event
=
new
FetchEvent
(
args
.
event
.
type
,
{
request
:
new
Request
(
args
.
event
.
request
.
url
+
'/format/webp'
),
clientId
:
args
.
event
.
clientId
,
isReload
:
args
.
event
.
isReload
});
// return useWebp;
// }, args => {
// // 重新构造 fetch 请求
// args.event = new FetchEvent(args.event.type, {
// request: new Request(args.event.request.url + '/format/webp'),
// clientId: args.event.clientId,
// isReload: args.event.isReload
// });
return
cacheFirstStrategy
.
handle
(
args
);
});
// return cacheFirstStrategy.handle(args);
// });
...
...
Please
register
or
login
to post a comment