# Preload dashboard data

## Overview

This consists of a toggle button that, when enabled, changes the widget logic so dashboard data is preloaded and available as the dashboard loads.

<figure><img src="/files/hkdxp7iWqDYseotGcubn" alt=""><figcaption></figcaption></figure>

Before this feature was added, users could only retrieve data from the Ubidots class by listening for an event and reading the required variable inside the callback.

For example, if you wanted to get your Ubidots token and the ID of the currently selected device, you could do it as follows:

```javascript
var ubidots = new Ubidots();

ubidots.on('ready', async function () 
{
	token = ubidots.token;	
	deviceID = ubidots.selectedDevice;		
});
```

However, this requires advanced JavaScript knowledge and familiarity with custom Ubidots events.

With **Preload dashboard data** enabled, you can access the same values directly:

```javascript
token = ubidots.token;	
deviceID = ubidots.selectedDevice;
```

There is no need to instantiate the Ubidots class, since an instance already exists.

{% hint style="danger" %}
By enabling this feature, the `ready` event shown above is no longer available.
{% endhint %}

## Class properties when *Preload dashboard data* is disabled

When *Preload dashboard data* is disabled, some class properties may appear as `undefined`. This happens because the class instance has not yet received their values. Consider the following code snippet:

```javascript
const ubidots = new Ubidots();

console.log(ubidots.token);
ubidots.on('receivedToken', function (token) {
    console.log(token);
    console.log(ubidots.token);
})
```

Although `ubidots.token` is valid syntax and the `Ubidots` class includes that property, the first `console.log` prints `undefined`. The other two print the token correctly because the property is only available after the event sets its value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ubidots.com/dashboards-and-widgets/html-canvas/preload-dashboard-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
