首页 > 解决方案 > 为什么我的文件没有通过 Service Broker 缓存?

问题描述

我确定了一个使 Service Broker 缓存操作失败的文件。或者更准确地说,让它什么都不缓存。我有一个包含要缓存的文件的数组。

当这个 'view/viewListAttentes.php' 被评论时,这个过程就起作用了,文件被添加到缓存存储中。但是当它不是时,“site-static-v9”被创建但为空。这个文件和其他文件一样在文件夹中。

那么您知道文件有什么问题会导致这种情况吗?

const staticCacheName = 'site-static-v9';
const assets = [
'/index.php',
'/css/global.css',
'/js/app.js',
'/js/rech.js',
'/js/rechFormFilm.js',
'/js/button.js',
'/modele/modele.php',
'/param/param.ini',
'/view/viewAjout.php',
'/view/viewFooter.php',
'/view/viewHeader.php',
// '/view/viewListAttentes.php', When commented it's working, else the cache is empty
'/view/viewMenuEnTete.php',
];

// installation of the Service Worker
self.addEventListener('install', e => {
    console.log('SW installé', e);
    e.waitUntil(
        caches.open(staticCacheName)
            .then(cache => {
                console.log('-------On cache en static les éléments----------');
                return cache.addAll(assets)
                            .then(e => {
                                console.log(e);
                            })
                            .catch(e => {
                                console.log("erreur addAll", e.message);
                            });
            })
            .catch(err => {
                console.log("erreur open cache", err.message);
            })
    );
});

标签: progressive-web-appsbrowser-cacheservice-broker

解决方案


我真的不知道为什么,但似乎这个文件中的一个标签使它无法缓存....奇怪,因为我有很多 .php 文件,这些标签使用 addAll() 方法缓存。

为了让它工作,我在 index.php 中移动了这个 php 标签。


推荐阅读