Using the Offline Mode: Requirements
Back to Using the Offline Mode.
Requirements
Section titled “Requirements”To use the offline mode, you need to fulfill the following requirements:
- Brezel with
^brezel-spa@3.8.0or higher, and^brezel/api@0.97.0or higher - A device with a browser that supports offline mode:
- Chrome
- Firefox
- Safari
- Edge
- For the service worker, you need to have a secure connection (HTTPS).
Limitations
Section titled “Limitations”The offline mode has some limitations:
- Workflows are not supported in offline mode. Requests made to workflows are instead queued and executed when the internet connection is available. Using workflows for pre-filling data is not recommended in offline mode. Instead, use Brezel Actions (to be documented).
- Storage of large file uploads, or requests in general, is limited to the browser’s IndexedDB size, which counts against the browser’s storage quota. If the storage quota is exceeded, the service worker will not be able to store the request and will return an error.
Levels
Section titled “Levels”Brezel has different levels of availability:
- Online: The application is connected to the internet and works as usual.
In this mode, the background sync queue is not used, although it may still hold requests that were made while offline and will be synchronized when the Browser fires the
syncevent. - Offline level 0: Used when the application is disconnected from the internet and the Brezel version is older than
brezel-spa@3.8.0. All requests result in a “No connection” (Failed to fetch) error. No background sync queue is available. - Offline level 1: Used when the application is disconnected from the internet, and
VITE_APP_OFFLINE_MODEin the.envfile is not set or set tofalse. In this mode, the service worker serves data from thespa-cache,abi-base-cacheand theapi-cf-cache, meaning that the application is visible and still navigable, but entities are not available. In the menu, the warning “You are offline” is displayed. Requests made to the API result in a “No connection” (Failed to fetch) error. The background sync queue is not available. - Offline level 2: Used when the application is disconnected from the internet and
VITE_APP_OFFLINE_MODEin the.envfile is set totrue. In this mode, the service worker serves data from thespa-cache,api-base-cache,api-cf-cache, andapi-nf-cache. In the menu under the logo, the warning “You are offline” is displayed. Entities and offline resource tables are available, if they were previously loaded or explicitly downloaded. Requests made to the API are intercepted by the service worker and served from the cache with normal status codes. The application feels like it is online, but data may be outdated. The background sync queue is used to store requests made while offline.
Pre-downloads
Section titled “Pre-downloads”In offline level 2, the service worker can pre-download data from the API after page load, or when the user clicks on the download button in the offline mode menu.
To make entities of a module downloadable, you need to set the offline option in the module’s options:
[ { "resource_module": "customers", "import": true, "resource": { "identifier": "customers", "title": "name", "icon": "global", "layouts": { "detail": "${file('/modules/customers.detail.json')}" }, "options": { "offline": { "enabled": true, "download": { "trigger": "manual" } } }, "fields": [ { "identifier": "name", "type": "text", "options": { "rules": "required" } } ] } }]The offline option has the following type signature:
type OfflineOptions = { enabled: boolean download: DownloadOptions}
export type DownloadOptions = { trigger?: 'auto' | 'manual' | null | undefined pages?: number | null | undefined filters?: DNF | null | undefined}
export type DNF = FilterClauses[]
export type FilterClauses = FilterClause[]
export type FilterClause = { column: string | undefined field: string | undefined operator: string value: string | unknown[] | unknown}