首页 > 解决方案 > php 脚本中标头重定向的 Service Worker 配置

问题描述

语言使用 php、html 和 js。我创建了一个只能通过 POST 完美运行的服务工作者脚本。当我尝试制作 header("Location: " . $MM_redirectLoginSuccess,TRUE,302); 其中 $MM_redirectLoginSuccess 是“aaaa.php”;应用程序循环 GET 和状态被取消,只要浏览器挂起错误太多重定向!。这是我可以从开发人员面板的网络选项卡中获得的。

fetch("https://xxxx.aaaa.php", {
  "referrer": "https://xxxx/",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "omit"
});

请问如何避免这个问题?上面的 fetch 插入到 ServiceWorker-->

self.addEventListener('fetch', event => {
  // Prevent the default, and handle the request ourselves.
  event.respondWith(async function() {
    // Try to get the response from a cache.
    const cachedResponse = await caches.match(event.request);
    // Return it if we found one.
    if (cachedResponse) return cachedResponse;
    // If we didn't find a match in the cache, use the network.
    return fetch(event.request);
  }());
});

标签: progressive-web-apps

解决方案


推荐阅读