Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

datapages-offline

БесплатноБез исполняемых скриптовНе проверен

The Datapages service worker: offline page snapshots and cached shims written by handlers through the pageCache parameter, the offline module and its Config…

romsharkот romshark★ 122 звезды на GitHub

Об этом скилле

Offline and instant loads

Read datapages first for the build loop, hard rules and naming conventions.

modules/offline serves a service worker and adds registration to HTML responses. Handlers write its cache through the pageCache datapages.PageCacheWriter parameter:

  • Snapshots (Set): served only while the browser is offline.
  • Shims (SetShim): served online too, at once, then replaced by the live page.

The worker runs only in a secure context (HTTPS or localhost). Everywhere else the API does nothing.

Configure the module

Declaring PageOffline generates a WithOffline option with that page's route:

// PageOffline is /offline
type PageOffline struct{ App *App }

func (PageOffline) GET(r *http.Request) (body datapages.Component, err error) {
	return pageOffline(), nil
}
opts := []datapages.ServerOption{
	// Self-host Datastar: the CDN is unreachable offline.
	datapages.WithDatastarJS(assets.Path("datastar-1.0.5.js")),
	datapagesgen.WithOffline(app.OfflineConfig()),
}
// OfflineWorkerVersion identifies the installed worker and its cache. Increment
// it after a Datapages upgrade or a change to Assets, ExcludePaths,
// CrossOriginDestinations, OfflineClass, or PageOffline. Changes to Assets or
// PageOffline require a new installation because the worker fetches them only
// during installation.
const OfflineWorkerVersion = 1

func OfflineConfig() offline.Config {
	return offline.Config{
		WorkerVersion: OfflineWorkerVersion,
		// Precache the files required to render cached pages offline.
		Assets: []string{
			assets.Path("style.css"), assets.Path("datastar-1.0.5.js"),
		},
	}
}

For shims without PageOffline, install the module directly:

offline.WithServiceWorker("", offline.Config{WorkerVersion: 1})
offline.Config field default
WorkerVersion 1; increment after a Datapages upgrade or a change to Assets, ExcludePaths, CrossOriginDestinations, OfflineClass, or PageOffline
ScriptURL /service-worker.js; the scope is the whole origin either way
Assets none; files cached during installation
OfflineClass is-offline, toggled on <html> while offline
CrossOriginDestinations image, style, script, font; empty non-nil disables
ExcludePaths none; same-origin prefixes never cached

Style offline state in CSS, no Go code:

.is-offline [data-needs-network] { opacity: .5; pointer-events: none }

Datapages compresses after WithOffline, so compressed pages keep the worker registration. Put a custom compressing middleware before WithOffline. An already encoded response passes through WithOffline unchanged and gets no worker registration.

Offline support writes inline scripts: the connectivity script, the worker registration and queued cache writes. Each script uses the nonce from WithCSPNonce. WithOffline reads the nonce when each request arrives, independent of option order. Set offline.Config.CSPNonce to use a different nonce for the connectivity and registration scripts. The queued cache writes always use the nonce from WithCSPNonce.

When offline.Config.CSPNonce is nil, offline.WithServiceWorker uses the nonce from WithCSPNonce. Calling offline.Middleware through datapages.WithMiddleware does not copy the server nonce. A nonce-only policy blocks the middleware scripts.

A cached page is rendered once and replayed. It cannot contain a valid per-response nonce. Its shim hydration trigger and connectivity script are written without one. The service worker provides no policy header, and the browser does not require a nonce. A Content-Security-Policy in a meta element would block those scripts.

PageOffline

PageOffline is reserved like PageError404 and PageError500. The worker caches it during installation and returns it for an uncached URL while offline. It renders with a zero Session. Datapages supplies a minimal default.

The pageCache parameter

The parameter is optional on GET methods and on page or *App actions.

method effect
Version() the version the client holds for this request's URL, 0 if none
Set(url, body, version) cache body for url, served only while offline
SetShim(url, body, version) cache body for url, served online too
Clear(url) remove 1 entry
ClearAll() remove every page cache entry

url comes from the generated href package. Writes remain queued until the handler returns without error. The worker then applies them together, with ClearAll first.

Version() covers this URL only. Caching any other URL is therefore unconditional.

Snapshots

func (p PagePost) GET(
	r *http.Request,
	pageCache datapages.PageCacheWriter,
	path datapages.Path[struct {
		Slug string `path:"slug"`
	}],
) (body datapages.Component, err error) {
	post, ok := p.App.Post(path.Values.Slug)
	if !
Полный SKILL.md на GitHub

Установить datapages-offline в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл datapages-offline?

The Datapages service worker: offline page snapshots and cached shims written by handlers through the pageCache parameter, the offline module and its Config, and the PageOffline fallback.

Как установить скилл datapages-offline?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл datapages-offline запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить datapages-offline с