跳过正文

Service Worker

首次發表:

The Service Worker intercepts network requests to serve cached assets as a fallback when offline, keeping the site accessible without a network connection.

The Service Worker is intentionally disabled in local development to prevent it from interfering with live page reloads and content updates.

Configuration

All keys go under params.sw in hugo.yaml.

KeyTypeDefaultDescription
sw.enablebooleanfalseRegisters and activates the Service Worker.
sw.precache.htmlbooleanfalseProactively cache all HTML pages in the background. Pages are fetched idly (one at a time) to avoid competing with user-initiated requests. HTML requests are always served network-first with offline fallback, regardless of this setting.
sw.precache.assetsbooleanfalseProactively cache critical assets during Service Worker installation, before the user visits any page. When disabled, assets are cached on first visit.
hugo.yaml
params:
  sw:
    enable: true
    precache:
      html: true
      assets: true

文章关联

无障碍设定

字体大小