I'm trying to develop PWA with codeigniter multilingual. We have placed the manifest.json and service-worker.js in the root path with index.php .
I believe CodeIgniter is searching the service worker in another path. The multilingual redirection is affecting it?
Error: No matching service worker detected. you may need to reload the page
Manifest.json
{
"name": "Project",
"short_name": "Project",
"theme_color": "#359daf",
2background_color": "#359DAF",
"display": "standalone",
"orientation": "portrait",
"Scope": "/",
"start_url": "/",
"icons": [
{
"src": "assets/img/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "assets/img/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"splash_pages": null
}
Register service worker
var url = window.location.href;
var swLocation = '/sw.js';
var swReg;
if ( navigator.serviceWorker ) {
window.addEventListener('load', function() {
navigator.serviceWorker.register( swLocation ).then( function(reg){
swReg = reg;
swReg.pushManager.getSubscription();
});
});
}
What is the correct file name for your Service Worker? service-worker.js or sw.js
If file name is service-worker.js , so You have to call the correct name
var swLocation = '/service-worker.js';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.