Service Worker 可以检测历史导航吗?

Can a service worker detect history navigation?

我有一个 service worker 在后台加载主要内容时显示启动画面。

不幸的是,这会使历史导航(例如,后退按钮)的体验变差,因为初始屏幕会丢失页面状态(例如,滚动位置)。

Service Worker 有没有办法检测到 FetchEvent 用于历史导航?

我相信通过 FetchEvent 接口公开的 Request 对象不会有任何具体标识它是由于历史导航引起的。例如,mode attribute 最终将被设置为 'navigate',这与您在导航中看到的值相同,因为除了后退按钮以外的其他内容。

FetchEvent 上有一个 isReload 属性,但是 service worker specification 特意指出只刷新,而不是历史导航,应该产生 true 值:

Pressing the refresh button should be considered a reload while clicking a link and pressing the back button should not. The behavior of the Ctrl+l enter is left to the implementations of the user agents.