> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Offline download manager

> Download documents and media files to the device so users can open them offline, and track progress with the JavaScript Bridge.

The Offline Download Manager plugin lets your app download and manage document and media files directly on the device. Users can access downloaded files without a network connection, and you can track download progress and manage files through a built-in interface or programmatically through the JavaScript Bridge.

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

## Why use offline download manager

Offline access removes dependency on network connectivity for content-heavy apps. Instead of streaming or re-fetching files on every visit, downloaded content is available instantly, even in airplane mode.

* **Document and media apps**: Let users download articles, PDFs, audio, or video for offline reading or playback.
* **Field service apps**: Ensure technicians can access manuals and forms when working in areas with no connectivity.
* **Training and education apps**: Allow learners to download course materials before a commute or travel.
* **Content subscription apps**: Enable subscribers to save content locally for offline consumption.

## Implementation guide

### JavaScript Bridge functions

Use the following JavaScript Bridge functions to initialize the download manager, start downloads, and display the file management UI.

#### Initialization

Create a JavaScript function to receive status events, e.g.

Median JavaScript Bridge

```javascript JavaScript theme={null}
function downloadCallback(data) {
  console.log(data);
}
```

Before starting any downloads, you will need to register your callback by running the following command using the Median JavaScript Bridge through HTML or JavaScript:

Median JavaScript Bridge

```javascript JavaScript theme={null}
{/* Note: This command returns a promise */}
<button onclick="median.downloads.init({'callback': downloadCallback})">
  Register Download Callback
</button>
```

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.downloads.init({ callback: downloadCallback }); // returns promise
```

#### Starting downloads

To start a download, run the following command using the Median JavaScript Bridge:

Median JavaScript Bridge

```javascript JavaScript theme={null}
<button onclick="median.downloads.downloadFile({'url': 'URL', 'title': 'Title'})">
  Start Download
</button>
```

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.downloads.downloadFile({ url: "URL", title: "Title" });
```

Params "url" and "title" are required, all others are optional. Supported parameters are:

* url: The URL of the file to download. Should start with http or https.
* title: The name to show in the UI.
* identifier (optional): a string used to identify the download in the downloadCallback function, so that multiple simultaneous downloads can be differentiated.
* details (optional): additional information to show below the title. A description of the download.
* date (optional): a date in yyyy-mm-dd format to show below the details. Can be used to show a publish date for a podcast, for example.

#### Following the download progress

After a download is started, the callback function will be called with a data object with the following fields:

* identifier: the identifier passed to the downloadFile command
* event: "progress", "done", or "error"

If event is "progress":

* bytesWritten: the number of bytes that have been downloaded
* expectedBytes: the file sized indicated by the server

If event is "error":

* errorMessage: A string indicating the reason for the error

### Showing UI

To show the download manager user interface, run the following command using the Median JavaScript Bridge:

Median JavaScript Bridge

```javascript JavaScript theme={null}
<button onclick="median.downloads.showUI()">Show Download Manager UI</button>
```

Median JavaScript Bridge

```javascript JavaScript  theme={null}
median.downloads.showUI(); 
```

### Offline page

Typically your app will cache the pages for display offline. To ensure the download manager UI can still be opened when the app if offline for an extended period configure an offline.html page within your app. See [Offline Page](https://docs.median.co/docs/offline-page) and review the sample offline page below or on [CodePen](https://codepen.io/gonative/pen/PoJbEEN).

[Offline File Manager - offline.html](https://codepen.io/gonative/embed/PoJbEEN?default-tab=html%2Cresult\&editable=false)

## Troubleshooting

### Offline download manager functions are undefined or not working

Ensure the JavaScript Bridge is enabled in Median App Studio. Define a `median_library_ready()` function on your page — Median calls it after the bridge has initialized. If the bridge may already be initialized before your function is defined, use the fallback check:

Median JavaScript Bridge

```javascript JavaScript theme={null}
function median_library_ready() {
  // safe to call median.downloads functions here
}

// fallback if bridge initialized before page loaded
if (window.median) {
  median_library_ready();
}
```

Also verify that `median.downloads.init` is called before `median.downloads.downloadFile`. See the [JavaScript Bridge Overview](https://docs.median.co/docs/javascript-bridge.md) for details.

### Callback does not receive events after downloadFile is called

Confirm that `median.downloads.init` was called with a valid callback before `downloadFile`. The callback must be registered before any download is started. Check the browser console for JavaScript errors in your callback function.

### Download manager UI is not accessible when offline

Configure an `offline.html` page in your app to ensure the download manager remains accessible when there is no network connectivity. Without this configuration, the download manager UI may not load when the device is offline. See [Offline Page configuration](https://docs.median.co/docs/offline-page) for setup instructions — note that all CSS/JS must be inlined and images must be Base64 or SVG.

## Offline download manager demo app

> [!NOTE]
>
> **Demo apps**
>
> In the sample applications below, you can explore how document and media files are downloaded, along with the callback responses that occur during the download process. Additionally, these apps demonstrate the functionality of the offline file manager. For a complete offline experience, we recommend downloading the Android app and switching to airplane mode after downloading at least one file.


## Related topics

- [Offline page](https://docs.median.co/docs/offline-page.md)
- [Service workers](https://docs.median.co/docs/service-workers.md)
- [Common Xcode issues](https://docs.median.co/docs/common-xcode-issues.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.