简体   繁体   English

使用服务工作线程时,如何在不缓存 angular 中的响应的情况下调用某些 api?

[英]How to call certain apis without caching a response in angular when using service worker?

I Have attached 2 images.我附上了 2 张图片。 First Image is the very fist time when I load the website where the service-worker is registered.第一张图片是我第一次加载注册 service-worker 的网站。 There are 2 arrow mark that shows 302 found and sets the cookies of session information.有2个箭头,显示302 found,设置session信息的cookies。 在此处输入图像描述

This is the second time (refer the below image), After I sign out and sign in again using google i am getting the below image as a response.这是第二次(参考下图),在我退出并使用谷歌再次登录后,我得到下图作为响应。 You can see from the image there are no cookies set and it is actually from service worker.你可以从图像中看到没有设置 cookies,它实际上来自 service worker。

在此处输入图像描述

This is my ngsw-config.json, from the docs Reference I have made it as "navigationRequestStrategy": "freshness", But still it doesnt work.这是我的 ngsw-config.json,来自文档参考,我将其设为“navigationRequestStrategy”:“新鲜度”,但它仍然不起作用。

{
  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
  "index": "/index.html",
  "navigationUrls": [
    "! /**/*callback*"
  ],
  "navigationRequestStrategy": "freshness",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/manifest.webmanifest",
          "/*.css",
          "/*.js"
        ]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ]
}

So the service worker was caching the api response and returned from the cache.所以 service worker 正在缓存 api 响应并从缓存中返回。 To bypass the service worker for certain apis.绕过某些 api 的 service worker。 Either add salt or use ngsw-bypass in the queryparams.在查询参数中添加盐或使用ngsw-bypass

Bypass Service Worker Caching in APIs 绕过 API 中的 Service Worker 缓存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 node.js - 如何使用 Service Worker 缓存 handlebars.js - node.js - how Caching handlebars.js using service worker 使用服务工作者时脱机重写URL - Rewrite URL offline when using a service worker 需要异步使用node,js调用两个api,并汇总两个api的响应 - Need to call two apis using node,js asynchronously and aggregate the response from both the apis 如何使用SailsJS调用Google API - How to call Google APIs using SailsJS 403 响应代码 - 使用 Cowin setu API 时请求被阻止 - 403 Response code - Request Blocked when using Cowin setu APIs 当其中一个端点不工作时,如何使用 axios.all() 调用多个 API? - How to call multiple APIs using axios.all() when one of the endpoints is not working? 我的服务工作者正在缓存诸如索引页之类的文本/html 文档,如何阻止它? - My service worker is caching text/html documents like index page, how to stop it? Angular 5 Service Worker 不使用 Express - Angular 5 service worker not working with Express Angular JS SPA:如何使用Angular Controller SPA调用Angular服务? - Angular JS SPA: How to Angular Controller SPA to call Angular service? 使用Angular2的服务工作者推送通知 - Service Worker Push Notifications with Angular2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM