Service Worker does not work in most of mobile browsers
I've got a static site with service worker onboard that is hosted at GitLab pages and perfectly works offline on my laptop but occasionally doesn't work offline almost in any mobile browser (works in Opera Mini, but not in mobile Chrome). So I'm trying to figure out what's wrong with it.
My service worker registration script which invokes at index.html in the root of my site:
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./serviceWorker.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
My service Worker itself:
let cache_v1 = 'cache_v1';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cache_v1)
.then(cache => cache.addAll(
[
'./',
'./index.html',
'./favicon.png',
'./dist/bundle.js',
'./dist/style.css',
'./src/icons/soyuz_apollo192.png',
'./src/icons/soyuz_apollo_apple_icon.png',
'./src/img/asia.png',
'./src/img/pustota.jpeg',
'./src/img/zima-min.jpg'
]
))
)
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(matching => {
return matching || fetch(event.request)
})
)
})
Tell me if there is something else you need to know to help
javascript service-worker
add a comment |
I've got a static site with service worker onboard that is hosted at GitLab pages and perfectly works offline on my laptop but occasionally doesn't work offline almost in any mobile browser (works in Opera Mini, but not in mobile Chrome). So I'm trying to figure out what's wrong with it.
My service worker registration script which invokes at index.html in the root of my site:
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./serviceWorker.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
My service Worker itself:
let cache_v1 = 'cache_v1';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cache_v1)
.then(cache => cache.addAll(
[
'./',
'./index.html',
'./favicon.png',
'./dist/bundle.js',
'./dist/style.css',
'./src/icons/soyuz_apollo192.png',
'./src/icons/soyuz_apollo_apple_icon.png',
'./src/img/asia.png',
'./src/img/pustota.jpeg',
'./src/img/zima-min.jpg'
]
))
)
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(matching => {
return matching || fetch(event.request)
})
)
})
Tell me if there is something else you need to know to help
javascript service-worker
1
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20
add a comment |
I've got a static site with service worker onboard that is hosted at GitLab pages and perfectly works offline on my laptop but occasionally doesn't work offline almost in any mobile browser (works in Opera Mini, but not in mobile Chrome). So I'm trying to figure out what's wrong with it.
My service worker registration script which invokes at index.html in the root of my site:
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./serviceWorker.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
My service Worker itself:
let cache_v1 = 'cache_v1';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cache_v1)
.then(cache => cache.addAll(
[
'./',
'./index.html',
'./favicon.png',
'./dist/bundle.js',
'./dist/style.css',
'./src/icons/soyuz_apollo192.png',
'./src/icons/soyuz_apollo_apple_icon.png',
'./src/img/asia.png',
'./src/img/pustota.jpeg',
'./src/img/zima-min.jpg'
]
))
)
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(matching => {
return matching || fetch(event.request)
})
)
})
Tell me if there is something else you need to know to help
javascript service-worker
I've got a static site with service worker onboard that is hosted at GitLab pages and perfectly works offline on my laptop but occasionally doesn't work offline almost in any mobile browser (works in Opera Mini, but not in mobile Chrome). So I'm trying to figure out what's wrong with it.
My service worker registration script which invokes at index.html in the root of my site:
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./serviceWorker.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
My service Worker itself:
let cache_v1 = 'cache_v1';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cache_v1)
.then(cache => cache.addAll(
[
'./',
'./index.html',
'./favicon.png',
'./dist/bundle.js',
'./dist/style.css',
'./src/icons/soyuz_apollo192.png',
'./src/icons/soyuz_apollo_apple_icon.png',
'./src/img/asia.png',
'./src/img/pustota.jpeg',
'./src/img/zima-min.jpg'
]
))
)
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(matching => {
return matching || fetch(event.request)
})
)
})
Tell me if there is something else you need to know to help
javascript service-worker
javascript service-worker
edited Jan 3 at 18:47
Pavel Rodionoff
asked Jan 3 at 18:18
Pavel RodionoffPavel Rodionoff
187
187
1
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20
add a comment |
1
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20
1
1
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027716%2fservice-worker-does-not-work-in-most-of-mobile-browsers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027716%2fservice-worker-does-not-work-in-most-of-mobile-browsers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
take a look at the Service Worker Compatability Chart
– Garrett Motzner
Jan 3 at 18:50
well, I use the latest Chrome available ( which currently is 71 ) it understands service workers
– Pavel Rodionoff
Jan 3 at 19:01
Chrome Android 71?
– Garrett Motzner
Jan 3 at 19:06
Chrome 71 for IOS
– Pavel Rodionoff
Jan 3 at 19:13
I believe chrome only wraps webkit in iOS, so I would use the mobile safari column for compatibility, just to be sure. But even so, looks like it should have basic support...
– Garrett Motzner
Jan 3 at 19:20