0

I am creating a progressive website www.seta-capital.com, on the inspector I do not receive any error, I see the registration of the service worker but the website doesn't load offline, Lighthouse tool says that no service worker is present and no manifest is fetched. Can you please tell me if I am doing something wrong?

I created my very simple manifest.json

{
  "short_name": "Seta",
 "name": "Seta Capital",
"icons": [
{
  "src": "../img/logo_no_writing.png",
  "type": "image/png",
  "sizes": "192x192"
},
{
  "src": "../img/logo_no_writing.png",
  "type": "image/png",
  "sizes": "512x512"
 }
],
 "start_url": "/",
 "background_color": "#3367D6",
 "display": "standalone",
 "scope": "/",
 "theme_color": "#3367D6"
}

In my index.php I added my Script to locate the json

And I added a service Worker registration script:

<script>
if('serviceWorker' in navigator) {
  navigator.serviceWorker
           .register('../js/sw.js')
           .then(function() { console.log("Service Worker Registered"); 
 });
 }
 </script>

Finally my sw.js file is:

self.addEventListener('install', function(e) {
 e.waitUntil(
   caches.open('setacapital').then(function(cache) {
     return cache.addAll([
       '../',
       '../index.php',
       '../css/Formcss.css',
       '../js/jquery-2.1.0.min.js',
       '../js/circle-progress.min.js',
       '../css/Formcss2.css',
       '../img/bg.jpg',

     ]);
   })
 );
});

self.addEventListener('fetch', function(event) {
 console.log(event.request.url);

 event.respondWith(
   caches.match(event.request).then(function(response) {
    return response || fetch(event.request);
   })
);
});

1 Answers1

0

that won't work.

your index.php is probably a complex dynamically creating file.. depending on a lot of other php code and database queries.

you would need to cache a pre-rendered file like an index.html file.

André Kelling
  • 1,575
  • 16
  • 23
  • Hi Andre', thank you very much for your feedback, but the Manifest file also is not working. So I suspect there is more, actually I can see the whole website cached in the Inspector – Tommaso Lazzari Nov 21 '18 at 03:56