---
url: https://talkjs.com/docs/UI_Components/Offline_Behavior/
title: "Offline behavior | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# Offline behavior

What users see when chat loses its connection.

If a user loses reception with chat open, they can still read messages that have loaded and type a reply. If they press Send, the message shows as **Sending**. When reception returns, chat reconnects automatically, sends the reply and shows new messages from the other participants. Edits and deletions made while offline also go through when chat reconnects.

## If the chat token expires

With refreshable tokens, the session calls your `onNeedToken` callback when it needs a fresh token. If the device is offline, retry the request to your backend inside that callback. Once you pass the new token to `session.setToken(token)`, chat resumes for the signed-in user. [Set up refreshable tokens](https://talkjs.com/docs/Features/Security/Advanced_Authentication/#refreshable-tokens)

## Photos and files

If a user selects a photo while offline, the upload starts when reception returns. If the connection drops during the upload and the upload fails, the user can select the file again once connected. Once the file has uploaded, pressing Send works the same way as sending text.

Users can still see images already displayed in the conversation. Opening an attachment that hasn't been downloaded needs a connection.

## If the user closes or reloads the page

Chat needs a connection to load conversation history again. Text left in the message field is saved on the device and restored when the user reopens that conversation. Pressing Send clears the draft.

Messages and changes that reached TalkJS appear in the history. Pending sends, edits and deletions that didn't reach TalkJS need to be submitted again. An unfinished upload needs to be selected again.
