【问题标题】:Hardcoded manifest start url still not found?仍然找不到硬编码的清单开始网址?
【发布时间】:2018-05-08 14:09:52
【问题描述】:

我正在尝试将 WordPress 主题设置为渐进式 Web 应用程序。当我运行 Chromes 审计工具(灯塔?)时,我收到一个无意义的错误,我不知道问题到底是什么。错误是:

失败:Service Worker 未成功提供清单 start_url。无法通过 service worker 获取启动 url

我已经硬编码了我的起始 url,这是一个有效的 url。有什么建议可以解决这个问题吗?

https://mywebsite.com/wp-content/themes/mytheme/web.manifest:

  ...
  "scope": "/",
  "start_url": "https://mywebsite.com",
  "serviceworker": {
    "src": "dist/assets/sw/service-worker.js",
    "scope": "/aw/",
    "update_via_cache": "none"
  },
  ...
}

https://mywebsite.com/wp-content/themes/mytheme/dist/assets/sw/service-worker.js:

...
// The fetch handler serves responses for same-origin resources from a cache.
// If no response is found, it populates the runtime cache with the response
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
  // Skip cross-origin requests, like those for Google Analytics.
  if (event.request.url.startsWith(self.location.origin)) {
    event.respondWith(
      caches.match(event.request).then(cachedResponse => {
        if (cachedResponse) {
          return cachedResponse;
        }

        return caches.open(RUNTIME).then(cache => {
          return fetch(event.request).then(response => {
            // Put a copy of the response in the runtime cache.
            return cache.put(event.request, response.clone()).then(() => {
              return response;
            });
          });
        });
      })
    );
  }
});

我使用以下代码注册了我的 SW,它输出它已成功注册 SW:

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register(Vue.prototype.$ASSETS_PATH + 'sw/service-worker.js')
  .then(function(registration) {
    console.log('Registration successful, scope is:', registration.scope);
  })
  .catch(function(error) {
    console.log('Service worker registration failed, error:', error);
  });
}

【问题讨论】:

    标签: wordpress manifest progressive-web-apps


    【解决方案1】:

    请将您的 start_url 更改为

     "start_url": "/"
    

    它必须是一个相对 url。请看documentaion

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-03
      • 2019-10-22
      • 1970-01-01
      • 2021-04-09
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多