Authored by 郭成尧

pwa

... ... @@ -43,25 +43,23 @@ function unregister() {
}
window.addEventListener('load', function() {
if (yoho.isApp) {
return;
}
if ('serviceWorker' in navigator && isHttps) {
$.ajax({
url: '//m.yohobuy.com/api/switch',
dataType: 'jsonp',
cache: false,
success(res) {
const usePwa = isHttps && res && res.usePwa;
if (!yoho.isApp) {
if ('serviceWorker' in navigator && isHttps) {
$.ajax({
url: '//m.yohobuy.com/api/switch',
dataType: 'jsonp',
cache: false,
success(res) {
const usePwa = isHttps && res && res.usePwa;
if (usePwa) {
register();
} else {
unregister();
if (usePwa) {
register();
} else {
unregister();
}
}
}
});
});
}
}
});
... ...
... ... @@ -95,11 +95,14 @@ workboxSW.router.registerRoute(args => {
if (/^https:\/\/m.yohobuy.com/.test(args.url.href) &&
(routeRegExp.test(args.url.pathname) ||
args.url.pathname === '/') ||
args.event.request.headers.get('x-requested-with') !== 'XMLHttpRequest') {
args.url.pathname === '/')) {
cached = true;
}
if (args.event.request.headers.get('x-requested-with') === 'XMLHttpRequest') {
cached = false;
}
return cached;
}, args => {
return workboxSW.strategies.networkFirst({
... ...
This diff could not be displayed because it is too large.