Last active
June 18, 2021 04:16
-
-
Save HasanQari/752b80039438bc29f52b3b1a6de37ce9 to your computer and use it in GitHub Desktop.
No matching service worker detected. You may need to reload the page, or check that the scope of the service worker for the current page encloses the scope and start URL from the manifest.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i have this error when i try to host pwa on github the pea works fine locally but not on github why?? | |
Failure reason | |
No matching service worker detected. You may need to reload the page, or check that the scope of the service worker for the current page encloses the scope and start URL from the manifest. | |
AND | |
this error in the console | |
A bad HTTP response code (404) was received when fetching the script. | |
My repo name: PWAPP | |
My project is: | |
{ | |
1-index.html | |
2-PWA *folder | |
-sw.js | |
-manifest.json | |
3-icon *folder has png image | |
} | |
####################################################### | |
My index.html | |
<title>Document</title> | |
<main> | |
<div id="content-area-start-page" class="container mb-5"> | |
<div id="frame-start-page" class="text-center align-content-center flex-column mt-5 py-3 px-4" | |
style="border: 3px solid #ccc; border-radius: 50%;"> | |
<img id="logo-start-page" src="res/img/icon.svg" alt="logo" class="img-fluid" width="70%"> | |
<h5 id="app-name-start-page" class="mb-3">App Name</h6> | |
<p id="app-description-start-page">مرحبا بكم في [اسم التطبيق] سهل وسريع</p> | |
<a id="btn-next-start-page" class="btn btn-primary" href="">التالي</a> | |
</div> | |
</div> | |
</main> | |
<!-- BS Js --> | |
<script src="asset/js/BSjs/bootstrap.min.js"></script> | |
<script src="asset/js/BSjs/bootstrap.js"></script> | |
<!-- Main Js --> | |
<script src="asset/js/app.js"></script> | |
<!-- Extra Js --> | |
<script> | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('PWAPP/service-worker.js', { scope: '/PWAPP/'}) | |
// ('/service-worker.js') | |
.then(function (registration) { | |
console.log("success load"); | |
console.log(registration); | |
}) | |
.catch(function (err) { | |
console.log(err); | |
}); | |
} | |
</script> | |
####################################################### | |
my sw.js | |
var APP_PREFIX = 'ApplicationName_' // Identifier for this app (this needs to be consistent across every cache update) | |
var VERSION = 'version_01' // Version of the off-line cache (change this value everytime you want to update cache) | |
var CACHE_NAME = APP_PREFIX + VERSION | |
var URLS = [ // Add URL you want to cache in this list. | |
'/PWAPP/', // If you have separate JS/CSS files, | |
'/PWAPP/index.html' // add path to those files here | |
] | |
// Respond with cached resources | |
self.addEventListener('fetch', function (e) { | |
console.log('fetch request : ' + e.request.url) | |
e.respondWith( | |
caches.match(e.request).then(function (request) { | |
if (request) { // if cache is available, respond with cache | |
console.log('responding with cache : ' + e.request.url) | |
return request | |
} else { // if there are no cache, try fetching request | |
console.log('file is not cached, fetching : ' + e.request.url) | |
return fetch(e.request) | |
} | |
// You can omit if/else for console.log & put one line below like this too. | |
// return request || fetch(e.request) | |
}) | |
) | |
}) | |
// Cache resources | |
self.addEventListener('install', function (e) { | |
e.waitUntil( | |
caches.open(CACHE_NAME).then(function (cache) { | |
console.log('installing cache : ' + CACHE_NAME) | |
return cache.addAll(URLS) | |
}) | |
) | |
}) | |
// Delete outdated caches | |
self.addEventListener('activate', function (e) { | |
e.waitUntil( | |
caches.keys().then(function (keyList) { | |
// keyList contains all cache names under your username.github.io | |
// filter out ones that has this app prefix to create white list | |
var cacheWhitelist = keyList.filter(function (key) { | |
return key.indexOf(APP_PREFIX) | |
}) | |
// add current cache name to white list | |
cacheWhitelist.push(CACHE_NAME) | |
return Promise.all(keyList.map(function (key, i) { | |
if (cacheWhitelist.indexOf(key) === -1) { | |
console.log('deleting cache : ' + keyList[i] ) | |
return caches.delete(keyList[i]) | |
} | |
})) | |
}) | |
) | |
}) | |
####################################################### | |
my manifest | |
{ | |
"name": "App Name", | |
"short_name": "App", | |
"start_url": "../", | |
"icons": [ | |
{ | |
"src": "../icons/manifest-icon-192.png", | |
"sizes": "192x192", | |
"type": "image/png", | |
"purpose": "maskable any" | |
}, | |
{ | |
"src": "../icons/manifest-icon-512.png", | |
"sizes": "512x512", | |
"type": "image/png", | |
"purpose": "maskable any" | |
} | |
], | |
"theme_color": "#3367D6", | |
"background_color": "#3367D6", | |
"display": "fullscreen", | |
"orientation": "portrait" | |
} | |
####################################################### | |
anybody can help me? | |
thank you so mush |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment