Offline support and caching

Offline support and caching

A portal can keep working when the device loses connectivity. When offline support is enabled, an offline worker installed on the device serves the portal page, its static resources and its data calls from a local cache according to a strategy you choose, shows a friendly page when a user navigates somewhere that was never cached, and queues writes made offline so they are sent as soon as the connection returns.

Offline support is off by default. You turn it on per portal.

Before you start: the mandatory Site step

Offline support depends on a second Visualforce page, PortalServiceWorker, being served from the portal's Site domain. Salesforce Sites only serve Visualforce pages that are listed under Setup, Sites, (your site), Site Visualforce Pages. That list is the guest profile's page access. Sites do not honour Visualforce page access granted through a permission set, so the fact that the Portals Guest permission set includes the page is not enough on its own.

Add PortalServiceWorker to Site Visualforce Pages, next to Portal:

  1. Setup, Sites, open your site.
  2. Click Edit next to Site Visualforce Pages.
  3. Move PortalServiceWorker into the Enabled Visualforce Pages list.
  4. Save.

The 11.1 package includes the updated Portal static resource with the offline worker script. For a deployment from source, deploy that resource together with PortalServiceWorker.

If you skip this step:

This step is mandatory on both a new install and an upgrade, and has to be repeated for every Site that serves a portal.

Turning offline support on

Two fields on the Web_Portal__c record, in the Offline and Caching layout section, control everything. Both are editable by users with the Portals Admin permission set. See Permission sets and access model.

Field Type Default Controls
Caching_Strategy__c Picklist NetworkOnly The strategy the offline worker applies to page, resource and data requests. NetworkOnly means offline support is off.
Cache_Max_Age_Minutes__c Number 120 How long a cached page, asset or data response is considered fresh, and how long a page template is kept in the on device template cache.

Picklist values:

Value Label
NetworkOnly Network Only (offline support off)
NetworkFirst Network First (network falling back to cache)
StaleWhileRevalidate Stale While Revalidate
CacheFirst Cache First (cache falling back to network)
CacheOnly Cache Only

Cache_Max_Age_Minutes__c applies to the on device page template cache regardless of which strategy is selected. Before this release that template cache was fixed at 120 minutes, so leaving the field at its default preserves the previous behaviour. A page with Disable_Caching__c ticked is still never template cached.

Who gets offline support

Offline support is registered only when both of these are true:

Internal users previewing a portal from inside the org (on the Visualforce domain) never get offline support. This keeps builder previews live and avoids caching an admin's view of a page.

What each strategy does

The offline worker intercepts three kinds of request:

Strategy Portal page Static resources Data calls
Network Only Always from the server. No cache. Always from the server. Always from the server.
Network First Try the server. Fall back to the cached page if the network fails. Try the server, fall back to cache. Try the server, fall back to the cached response if the network fails.
Stale While Revalidate Serve the cached page immediately, fetch a fresh copy in the background. Serve from cache, refresh in the background. Answer from cache immediately, refresh in the background. If the refreshed data differs, a cache update notification fires so the component can re-render.
Cache First Serve the cached page while it is younger than Cache Max Age, otherwise fetch. Same. Serve the cached response while it is younger than Cache Max Age, otherwise fetch.
Cache Only Only ever served from cache. Never goes to the network. Same. Same.

Choosing a strategy:

Passkey requests always require a connection. Settings, enrolment, sign-in, credential lists and revocation bypass browser response caches, portal data caches and offline queues, even under Cache First or Cache Only. Cached portal access does not provide offline passkey authentication. See Passkey login.

Report rows require a connection. The Report List catalogue can be cached, but opening a report loads its rows from the server. Report rows are excluded from the device cache.

Writes are never cached. Every write is sent to the network regardless of strategy. When the network is down, eligible writes are queued for background sync instead (see below).

Transport change for guest and community users

When offline support is active, guest and community users call Apex through the REST route, /services/apexrest/b3p/GlobalRemotingRouter/, instead of Visualforce remoting. This is what allows the offline worker to see, cache and queue data traffic, because a remoting call is not an interceptable network request.

Nothing else changes:

The one environmental dependency is that the Site domain must actually serve /services/apexrest. See troubleshooting.

The offline page

If a user navigates while offline to a page that was never cached, the portal shows a generic Page not available while offline page with a Retry button. This covers both a hard browser reload and in app navigation inside the portal. Retry re-attempts the navigation, so it resolves as soon as connectivity returns.

Toast messages the user will see

When Style Message
The connection drops Warning You are offline...
The connection returns Success You are back online.
A write is queued because the device is offline Info Your change has been saved on this device and will be sent when you reconnect.
The queue is replayed Success N changes made offline have been sent.

Background sync for offline writes

When the device is offline, write actions from the standard components are placed in a device local queue rather than failing.

Queued actions:

Component Actions
Dynamic Form, Record Data Table, Kanban Board, Calendar, Record Path saveRecord, updateRecord, deleteRecord
Activity & Task Manager saveActivity, completeActivity, reopenActivity, deleteActivity
Notifications Centre markViewed, markAllViewed, dismiss

File uploads are not queued. A file upload attempted offline fails as it did before. Ask users to retry uploads once they are back online.

How the queue behaves:

Logging out

Logging out purges the offline caches on that device. This prevents one portal user's cached pages and data being served to the next person who signs in on a shared or family device.

Troubleshooting