PWA API
Faststrap's PWA helpers provide a generated manifest, service-worker route, offline fallback, and registration script without making PWA behavior mandatory for ordinary FastHTML apps.
PwaMeta
Use PwaMeta(...) when you need the generated manifest link and mobile metadata without registering routes or a service worker yourself.
from faststrap import PwaMeta
head = PwaMeta(
name="Operations Console",
short_name="Ops",
icon_path="/assets/icon.png",
)
add_pwa
Use add_pwa(app, ...) for the complete integration. It registers the manifest and service-worker routes and injects the required metadata and registration script.
from fasthtml.common import FastHTML
from faststrap import add_bootstrap, add_pwa
app = FastHTML()
add_bootstrap(app)
add_pwa(
app,
name="Operations Console",
icon_path="/assets/icon.png",
cache_name="ops-console",
cache_version="v2",
pre_cache_urls=("/health",),
)
Important boundaries:
- Use a square PNG for the default icon path when broad install compatibility matters.
enable_background_syncandenable_pushprovide service-worker foundations; queue persistence, authentication, and push subscription storage remain application responsibilities.- Set
service_worker=Falsewhen the application owns its own service-worker route. - Review
scope,start_url, and cache policies when deploying below a subpath.
API Reference
faststrap.pwa.core.PwaMeta(name=None, short_name=None, theme_color='#ffffff', background_color='#ffffff', description=None, icon_path=_DEFAULT_ICON_PATH, icon_192=None, icon_512=None, manifest_path='/manifest.json')
Generate PWA meta tags and link elements.
These tags are essential for: - Installing the app on mobile home screens - Setting the theme color of the browser bar - Defining icons for different platforms (iOS/Android)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Full name of the application |
None
|
short_name
|
str | None
|
Short name for home screen (12 chars max recommended) |
None
|
theme_color
|
str
|
Color of the browser toolbar |
'#ffffff'
|
background_color
|
str
|
Background color for splash screen |
'#ffffff'
|
description
|
str | None
|
Description of the app |
None
|
icon_path
|
str
|
Path to the main icon (should be square, ideally 512x512) |
_DEFAULT_ICON_PATH
|
icon_192
|
str | None
|
Optional dedicated 192x192 icon path |
None
|
icon_512
|
str | None
|
Optional dedicated 512x512 icon path |
None
|
manifest_path
|
str
|
URL path to the manifest file |
'/manifest.json'
|
Returns:
| Type | Description |
|---|---|
tuple[Any, ...]
|
Tuple of FastHTML Meta and Link elements |
Source code in src/faststrap/pwa/core.py
faststrap.pwa.core.add_pwa(app, name='Faststrap App', short_name='Faststrap', description='A Progressive Web App built with Faststrap', theme_color='#ffffff', background_color='#ffffff', icon_path=_DEFAULT_ICON_PATH, icon_192=None, icon_512=None, display='standalone', start_url='/', scope='/', service_worker=True, offline_page=True, cache_name='faststrap-app', cache_version='v1', pre_cache_urls=None, use_cdn=None, enable_background_sync=False, background_sync_tag='faststrap-background-sync', route_cache_policies=None, enable_push=False, default_push_title='Faststrap Notification')
Enable PWA capabilities for the FastHTML app.
This helper:
1. Injects PWA meta tags into app headers
2. Serves a generated manifest.json
3. Serves a standard sw.js Service Worker (if enabled)
4. serves an /offline route (if enabled)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
FastHTML application instance |
required |
name
|
str
|
App name |
'Faststrap App'
|
short_name
|
str
|
App short name |
'Faststrap'
|
description
|
str
|
App description |
'A Progressive Web App built with Faststrap'
|
theme_color
|
str
|
Theme color |
'#ffffff'
|
background_color
|
str
|
Splash screen background color |
'#ffffff'
|
icon_path
|
str
|
Path to icon file |
_DEFAULT_ICON_PATH
|
icon_192
|
str | None
|
Optional dedicated 192x192 icon path for the manifest and touch icon |
None
|
icon_512
|
str | None
|
Optional dedicated 512x512 icon path for the manifest/tile icon |
None
|
display
|
str
|
Display mode (standalone, fullscreen, minimal-ui, browser) |
'standalone'
|
start_url
|
str
|
URL to open on launch |
'/'
|
scope
|
str
|
Scope of the PWA |
'/'
|
service_worker
|
bool
|
Enable automatic Service Worker |
True
|
offline_page
|
bool
|
Enable automatic /offline route |
True
|
cache_name
|
str
|
Service worker cache name prefix |
'faststrap-app'
|
cache_version
|
str
|
Cache version suffix used for cache invalidation |
'v1'
|
pre_cache_urls
|
Sequence[str] | None
|
Optional extra URLs to precache (in addition to defaults) |
None
|
use_cdn
|
bool | None
|
Force CDN-aware precache defaults; when omitted this is auto-detected |
None
|
enable_background_sync
|
bool
|
Enable Background Sync foundation hooks |
False
|
background_sync_tag
|
str
|
Tag used for Background Sync registrations |
'faststrap-background-sync'
|
route_cache_policies
|
dict[str, str] | None
|
Optional route prefix -> strategy mapping values: "network-first", "stale-while-revalidate", "cache-first" |
None
|
enable_push
|
bool
|
Enable push notification service worker handlers |
False
|
default_push_title
|
str
|
Fallback push notification title |
'Faststrap Notification'
|
Source code in src/faststrap/pwa/core.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |