pwa - добавить несколько URI - PullRequest
       12

pwa - добавить несколько URI

0 голосов
/ 20 сентября 2019

Я использую Symfony и добавляю PWA в свое приложение .. В моем приложении я использую веб-пакет У меня есть два файла js front.js и admin.js .. В двух файлах я запускаю сервисный работник и создаю файлы предварительного кэширования js и CSSдля домашней страницы '/' также я добавляю '/ admin' и '/ offline' в precache..но в режиме offline '/' и '/ offline' работает, но '/ admin' не работает !!это manifest.json:

{
  "name" : "test",
  "short_name" : "test",
  "icons": [
    {
    "src": "img/icon72x72.png",
    "type": "image/png",
    "sizes": "72x72"
  },{
    "src": "img/icon96x96.png",
    "type": "image/png",
    "sizes": "96x96"
  },{
    "src": "img/icon144x144.png",
    "type": "image/png",
    "sizes": "144x144"
  },{
    "src": "img/icon-48x48.png",
    "type": "image/png",
    "sizes": "48x48"
  },{
    "src": "img/icon512x512.png",
    "type": "image/png",
    "sizes": "512x512"
  }, {
    "src": "img/icon-192x192.png",
    "type": "image/png",
    "sizes": "192x192"
  }],
  "theme_color" : "#1a1a1a",
  "background_color" : "#1a1a1a",
  "start_url" : "/",
  "display" : "standalone",
  "orientation" : "natural"
}

sw.js:

var CACHE = 'pwa';

        self.addEventListener('install', function(event) {
            event.waitUntil(
                caches.open(CACHE).then(function(cache) {
                    fetch('/get-all-files?url='+event.target.location.origin)
                        .then(
                            function(response) {
                                if (response.status !== 200) {
                                    console.log('Looks like there was a problem. Status Code: ' +
                                        response.status);
                                    return;
                                }
                                response.json().then(function(data) {
                                    data.forEach(function(element) {
                                        if(element){
                                            cache.add(element);
                                        }
                                    });
                                    cache.add('/');
                                    cache.add('/offline');
                                    cache.add('/build/front.css');
                                    cache.add('/build/images/hp-slider.ca2e5f82.jpg');
                                    cache.add('/build/images/background-commentcamarche.15892cd8.jpg');
                                    cache.add('/build/images/background-etapes.15c039e3.jpg');
                                    cache.add('/FrontOffice/images/logo-marypop-en.png');
                                    cache.add('/FrontOffice/images/logo-marypop-fr.png');
                                    cache.add('/FrontOffice/images/logo-marypop-de.png');
                                    cache.add('/admin/');
                                    return true;
                                });
                            }
                        );
                })
            );
        });

        self.addEventListener('activate', function(event) {
            event.waitUntil(
                caches.keys().then(function(CACHE) {
                    return Promise.all(
                        CACHE.filter(function(CACHE) {
                            // Return true if you want to remove this cache,
                            // but remember that caches are shared across
                            // the whole origin
                        }).map(function(CACHE) {
                            return caches.delete(CACHE);
                        })
                    );
                })
            );
        });

        self.addEventListener('fetch', function(event) {
            event.respondWith(
                caches.match(event.request)
                    .then(function(response) {
                        // Cache hit - return response
                        if (response) {
                            return response;
                        }
                        return fetch(event.request).then(
                            function(response) {
                                // Check if we received a valid response
                                if(!response || response.status !== 200 || response.type !== 'basic') {
                                    return response;
                                }
                                var responseToCache = response.clone();
                                caches.open(CACHE)
                                    .then(function(cache) {
                                        cache.put(event.request, responseToCache);
                                    });

                                return response;
                            }
                        ).catch(function(err) {
                            return caches.open(CACHE)
                                .then(function(cache) {
                                    return cache.match('/offline');
                                });
                        });
                    })
            );
        });

как добавить '/' и '/admin' (часть панели инструментов для предварительного кэширования) также при добавлении'/register' в докеше работает в автономном режиме

...