大网数据广告活动
Web 标准与前端开发

Request: isReloadNavigation property

· 52CE 我爱测

The **`isReloadNavigation`** read-only property of the Request interface is a boolean indicating whether the request is a user-triggered reload.

Fetch API

The isReloadNavigation read-only property of the Request interface is a boolean indicating whether the request is a user-triggered reload.

A user-triggered reload can be triggered via a browser control, such as pressing <kbd>Cmd</kbd>/<kbd>Ctrl</kbd> + <kbd>R</kbd> or clicking the browser's reload button, or programmatically (for example, by calling Location.reload(), History.go(), or Navigation.reload()).

This property is primarily used within service worker ServiceWorkerGlobalScope.fetch_event event handlers to respond appropriately to reload requests versus non-reload requests. For example, a reload request indicates that the user expects current data, so it should prefer content from the server over that from a cache.

Value

A boolean value.

Examples

Basic usage

The following example can be used inside a service worker script to check for reloads and respond appropriately.

Inside a ServiceWorkerGlobalScope/fetch_event event handler, we first check whether the event's Request.mode is navigate and isReloadNavigation properties are true. If so, this is a reload navigation; we therefore fetch the page from the network to provide an updated version. If that fails, we try retrieving the page from the Cache as a fallback.

If the navigation is not a reload navigation, we try retrieving the page from the Cache first, and only fetch from the network if a cached version of the page is not found.

self.addEventListener("fetch", (event) => {
  if (event.request.mode === "navigate" && event.request.isReloadNavigation) {
    event.respondWith(
      fetch(event.request).catch(() => caches.match(event.request)),
    );
  } else {
    event.respondWith(
      caches
        .match(event.request)
        .then((cached) => cached || fetch(event.request)),
    );
  }
});

Specifications

Browser compatibility

See also

  • Navigation API

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。