Skip to main content

$service-worker

import { const base: string

The base path of the deployment. Typically this is equivalent to config.kit.paths.base, but it is calculated from location.pathname meaning that it will continue to work correctly if the site is deployed to a subdirectory. Note that there is a base but no assets, since service workers cannot be used if config.kit.paths.assets is specified.

base
, const build: string[]

An array of URL strings representing the files generated by Vite, suitable for caching with cache.addAll(build). During development, this is an empty array.

build
, const files: string[]

An array of URL strings representing the files in your static directory, or whatever directory is specified by config.kit.files.assets. You can customize which files are included from static directory using config.kit.serviceWorker.files

files
, const prerendered: string[]

An array of pathnames corresponding to prerendered pages and endpoints. During development, this is an empty array.

prerendered
, const version: string

See config.kit.version. It’s useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.

version
} from '$service-worker';

此模块仅在 service workers 中可用。

base

部署的 base 路径。通常这等同于 config.kit.paths.base,但它是从 location.pathname 计算得出的,这意味着即使网站部署到子目录中,它也能正常工作。

注意这里有 base 但没有 assets,因为当指定了 config.kit.paths.assets 时不能使用 service workers。

const base: string;

build

一个由 Vite 生成的文件的 URL 字符串数组,适合用 cache.addAll(build) 进行缓存。在开发过程中,这是一个空数组。

const build: string[];

files

一个由静态目录(或由 config.kit.files.assets 指定的任何目录)中的文件的 URL 字符串数组。您可以使用 config.kit.serviceWorker.files 自定义 static 目录包含的文件。

const files: string[];

prerendered

一个对应于预渲染页面和端点的路径名数组。在开发过程中,这是一个空数组。

const prerendered: string[];

version

参见config.kit.version。它在 service workers 内生成唯一的缓存名称时很有用,这样您的应用程序的后续部署可以使旧的缓存失效。

const version: string;

在 GitHub 编辑此页面

上一页 下一页