[英]How to handle custom code in Ngsw - in Fetch event
I was having service worker implemented in angular.js application where we have some custom code written in self.addEventListener('fetch', function (event)
. Now i am planning to migrate the application to angular, and i found in angular we have the special plugin which will do all configuration and cache cleanup. "@angular/service-worker": "~10.0.6",
. I was having service worker implemented in angular.js application where we have some custom code written in
self.addEventListener('fetch', function (event)
. Now i am planning to migrate the application to angular, and i found in angular we have将执行所有配置和缓存清理的特殊插件。 "@angular/service-worker": "~10.0.6",
.
Now i am suffering to have the custom code implemented inside fetch event to integrate in angular version.现在我很难在 fetch 事件中实现自定义代码以集成到 angular 版本中。 Is there any way we can have the fetch method override in to a component and do the operation from there.
有什么方法可以让 fetch 方法覆盖到组件中并从那里执行操作。
Based on your message this steps were done using angular-cli@10.0.6 .根据您的消息,这些步骤是使用angular-cli@10.0.6完成的。
<project_name>/node_modules/@angular/service-worker/ngsw-worker.js
<project_name>/node_modules/@angular/service-worker/ngsw-worker.js
handleFetch function
Line 1121.handleFetch function
第 1121 行。handleFetchWithFreshness
and handleFetchWithPerformance
as examples.handleFetchWithFreshness
和handleFetchWithPerformance
作为示例。npx patch-package @angular/service-worker
postinstall script
to package.json
postinstall script
添加到package.json
"scripts": {
"postinstall": "patch-package"
}
patch-package
package npm install --save-dev patch-package
patch-package
package npm install --save-dev patch-package
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.