首页 > 解决方案 > PWA 在 google chrome 中运行,但在 firefox 中运行

问题描述

因此,我决定将我的网站测试为 PWA,它适用于 google chrome,但不适用于 firefox(移动)。

我的 index.html 头中有这个

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>MYWEBSITE</title>

    <!--Website Icon-->
    <link rel="icon" type="image/svg+xml" href="images/favicon.svg">
    <link rel="alternate icon" href="images/favicon.png">

    <!--Stylesheets-->
    <link rel="stylesheet" href="css/style.css">

    <!--PWA-->
    <link rel="manifest" href="manifest.webmanifest">
    <script>
        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('sw.js');
        };
    </script>
</head> 

我的 manifest.webmanifest

{
    "name": "Progressive Web App",
    "short_name": "Site",
    "description": "Stuff",
    "icons": [{
            "src": "/images/favicon.svg",
            "type": "image/svg+xml",
            "sizes": "192x192"
        },
        {
            "src": "/images/favicon.svg",
            "type": "image/svg+xml",
            "sizes": "512x512"
        },
        {
            "src": "icon/fox-icon.png",
            "sizes": "192x192",
            "type": "image/png"
        }
    ],
    "start_url": "index.html",
    "background_color": "#000000",
    "display": "standalone",
    "theme_color": "#91e7ee"
}

和 sw.js

// On install - caching the application shell
self.addEventListener('install', function(event) {
    event.waitUntil(
        caches.open('sw-cache').then(function(cache) {
            // cache any static files that make up the application shell
            return cache.add('index.html');
        })
    );
});

// On network request
self.addEventListener('fetch', function(event) {
    event.respondWith(
        // Try the cache
        caches.match(event.request).then(function(response) {
            //If response found return it, else fetch again
            return response || fetch(event.request);
        })
    );
});

我的代码中没有添加任何其他内容我还缺少什么?因为我已经搜索过,一切都应该但它没有?

标签: htmlprogressive-web-apps

解决方案


推荐阅读