Skip to content

Commit 5be065e

Browse files
image and text edits
1 parent f6b43af commit 5be065e

File tree

8 files changed

+63
-51
lines changed

8 files changed

+63
-51
lines changed

modules/ROOT/pages/prerender.adoc

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
= Pre-rendering ThoughtSpot Embed Components
1+
= Pre-render ThoughtSpot Embed Components
22
:toc: true
33
:toclevels: 3
44

55
:page-title: Pre-rendering for Fast Embeds
66
:page-pageid: prerender
77
:page-description: How to use pre-rendering to optimize performance and user experience in ThoughtSpot embedding
88

9-
== Load Flow Diagrams
9+
This document explains the different pre-render strategies, when to use each, and how to implement them in React or JavaScript.
10+
11+
== Load flow of embed
1012

1113
The following diagrams illustrate how ThoughtSpot embed components load in a typical application, both for normal and pre-rendered scenarios. Reviewing these will help set the context for the strategies described in this guide.
1214

1315
image::./images/pre-render/embed_load.png[]
1416
image::./images/pre-render/liveboardEmbed_load.png[]
1517

16-
== How Embedding Normally Works (The Basics)
18+
== How embedding normally works
1719

18-
When you embed ThoughtSpot (or any analytics app) in your application, the typical flow is:
20+
When you embed ThoughtSpot in your application, the typical flow is:
1921

2022
. The user navigates to a page with the embed component.
21-
. The embed component is rendered in the DOM.
22-
. The browser loads the ThoughtSpot iframe and all required assets (JS, CSS, etc).
23-
. The iframe initializes, fetches data, and finally displays the analytics.
23+
. The embed component is rendered in the Document Object Model (DOM).
24+
. The browser loads the ThoughtSpot iframe and all required assets, such as JS, CSS, and so on.
25+
. The iframe initializes, fetches data, and finally displays the analytics content.
2426

25-
This means *every time* a user visits the page, the iframe and all assets are loaded from scratch, causing a visible delay before analytics appear.
27+
This means that *every time* a user visits the page, the iframe and all assets are loaded from scratch, resulting in a noticeable delay before the analytics appear.
2628

2729
image::./images/pre-render/embed_load.png[]
2830

29-
== What is Pre-rendering?
31+
== What is pre-rendering?
3032

3133
Pre-rendering changes this flow by *loading some or all of the assets and initialization steps in the background*, before the user actually navigates to the analytics. This way, when the user visits the page, the analytics are ready to show instantly (or much faster).
3234

3335
[NOTE]
3436
====
35-
Pre-rendering is most effective when your application has a loading page, landing page, or pre-embed page where you can start the pre-render process before the user navigates to the analytics. If a user navigates directly to the embed page (for example, via a direct link or bookmark), pre-rendering cannot provide a speed benefit because there is no opportunity to load assets in advance.
37+
Pre-rendering is most effective when your application includes a loading page, landing page, or pre-embed page. These pages allow you to initiate the pre-rendering process before the user navigates to the embedded content. However, if a user goes directly to the embed page, by either clicking a direct link or using a bookmark, pre-rendering will not provide any advantage in terms of loading speed, because there is no opportunity to load assets in advance.
3638
====
3739

38-
Pre-rendering can preload just the common assets, or even a specific liveboard, depending on your needs. The rest of this doc explains the different strategies and how to use them.
39-
40-
Pre-rendering lets you load ThoughtSpot embed components in the background, so users see analytics instantly when they navigate to them. This doc explains the different pre-render strategies, when to use each, and how to implement them in React or JavaScript.
40+
Pre-rendering can preload just the common assets, or even a specific Liveboard, depending on your needs. It lets you load ThoughtSpot embed components in the background, so users see analytics instantly when they navigate to them. The rest of this document explains different strategies and how to use them.
4141

42-
== Why Pre-render?
42+
== Why pre-render?
43+
Pre-rendering offers the following advantages:
4344

4445
* Reduce wait times for embedded analytics
4546
* Improve perceived performance and user experience
4647
* Choose the right tradeoff between speed and resource usage
4748

48-
== Embed Load Strategies
49+
== Embed load strategies
4950

50-
=== 1. Prerender with Liveboard ID
51+
=== Pre-render with Liveboard ID
5152

52-
- Fully loads the embed iframe, including all assets and liveboard data, as soon as the component is rendered.
53-
- Fastest experience for a specific liveboard.
54-
- Maximum resource usage if the user never views the embed.
53+
This method allows you to:
54+
- fully load the embed iframe, including all assets and Liveboard data, as soon as the component is rendered.
55+
- provide the fastest access to the specified Liveboard.
56+
- allow maximum resource usage if the user never views the embed.
5557

5658
To use this strategy, place the following component on your application's home page, loading page, or landing page (before the user navigates to the analytics):
5759

@@ -65,12 +67,12 @@ To use this strategy, place the following component on your application's home p
6567

6668
The value of `preRenderId` can be any string, but it must match the `preRenderId` you use when rendering the actual embed later.
6769

68-
[NOTE]
70+
[IMPORTANT]
6971
====
70-
Limitation: Any props you want to pass to the embed (such as configuration options) must be passed to the `PreRenderedLiveboardEmbed` component on the home page. If you later render a `LiveboardEmbed` with the same `preRenderId`, those new props will not be respected if the iframe is already loaded. This is a current limitation of the pre-rendering approach.
72+
If you want to pass props such as configuration options to the embed, note that these props must be passed to the `PreRenderedLiveboardEmbed` component on the homepage. If you later render a `LiveboardEmbed` with the same `preRenderId` after the iframe has loaded, the new props will not be applied. This is a known limitation of the pre-rendering approach.
7173
====
7274

73-
[example]
75+
[source,typescript]
7476
----
7577
// React example
7678
import { LiveboardEmbed } from "@thoughtspot/visual-embed-sdk/react";
@@ -86,11 +88,12 @@ const PreRenderLiveboardWithLiveboardId = () => (
8688

8789
image::./images/pre-render/pre_render_with_liveboard_id.png[]
8890

89-
=== 2. Prerender without Liveboard ID
91+
=== Pre-render without Liveboard ID
92+
This method offers the following advantages:
9093

91-
- Loads common assets and bootstrap logic early.
92-
- Defers liveboard-specific data/API calls until needed.
93-
- Keeps the app ready, making the first liveboard load faster.
94+
- Loads common assets and bootstrap logic early
95+
- Defers Liveboard-specific data/API calls until needed.
96+
- Keeps the app ready, making the first Liveboard load faster.
9497
- Still loads some assets even if the user never opens the embed.
9598

9699
To use this strategy, place the following component on your application's home page, loading page, or landing page:
@@ -104,12 +107,15 @@ To use this strategy, place the following component on your application's home p
104107

105108
Again, the value of `preRenderId` can be any string, but it must match the `preRenderId` you use when rendering the actual embed later.
106109

107-
[NOTE]
110+
[IMPORTANT]
108111
====
109112
Limitation: Any props you want to pass to the embed must be passed to the `PreRenderedLiveboardEmbed` component on the home page. If you later render a `LiveboardEmbed` with the same `preRenderId`, those new props will not be respected if the iframe is already loaded.
113+
114+
If you want to pass props such as configuration options to the embed, note that these props must be passed to the `PreRenderedLiveboardEmbed` component on the homepage. If you later render a `LiveboardEmbed` with the same `preRenderId` after the iframe has loaded, the new props will not be applied. This is a known limitation of the pre-rendering approach.
115+
110116
====
111117

112-
[example]
118+
[source,typescript]
113119
----
114120
// React example
115121
import { LiveboardEmbed } from "@thoughtspot/visual-embed-sdk/react";
@@ -125,22 +131,24 @@ const PreRenderLiveboardWithoutLiveboardId = () => (
125131

126132
image::./images/pre-render/prerender_without_liveboard_id.png[]
127133

128-
=== 3. Prerender On Demand
134+
=== Pre-rendering on demand
129135

130-
- Loads nothing up front; the embed is loaded only when the user navigates to it.
131-
- On first visit, the embed loads normally; on return, the iframe is reused and appears instantly.
132-
- Most efficient; only loads if needed, and reuses the iframe for instant reloads.
136+
This method offers the following advantages:
137+
138+
* It does not load anything upfront; the embed is only loaded when the user navigates to it.
139+
- On the first visit, the embed loads normally. On subsequent visits, the iframe is reused and appears instantly.
140+
- It is highly efficient, as it only loads when needed and reuses the iframe for instant reloads.
133141

134142
When you render a component with a `preRenderId` for the first time, it loads as usual. The next time you render a component with the same `preRenderId`, the load is instant because the iframe is reused.
135143

136-
This strategy does not require special configuration—simply pass a `preRenderId` prop to your normal component render:
144+
This strategy does not require special configuration. Just pass a `preRenderId` prop to your normal component render:
137145

138146
[source,jsx]
139147
----
140148
<LiveboardEmbed preRenderId="pre-render-on-demand" className="embed-div" />
141149
----
142150

143-
[example]
151+
[source,typescript]
144152
----
145153
// React example
146154
import { LiveboardEmbed } from "@thoughtspot/visual-embed-sdk/react";
@@ -152,13 +160,14 @@ const PreRenderEmbedOnDemand = () => (
152160

153161
image::./images/pre-render/preRender_on_demand.png[]
154162

155-
=== 4. Normal Render
163+
=== Normal render
164+
This is the default rendering method, which has both advantages and limitations:
156165

157-
- Default behavior; loads the embed only when the component is rendered.
158-
- On every visit, the iframe is recreated and the embed loads from scratch.
159-
- Efficient if the embed is rarely used, but slow for the user every time.
166+
* Loads the embed only when the component is rendered.
167+
* On every visit, the iframe is recreated and the embed loads from scratch.
168+
* Efficient if the embed is rarely used, but slow for the user every time.
160169

161-
[example]
170+
[source,typescript]
162171
----
163172
// React example
164173
import { AppEmbed } from "@thoughtspot/visual-embed-sdk/react";
@@ -168,20 +177,23 @@ const NormalEmbed = () => <AppEmbed className="embed-div" />;
168177

169178
image::./images/pre-render/normal_embed_load.png[]
170179

171-
=== 5. Prefetch
180+
=== prefetch
181+
This method prefetches common assets:
172182

173183
- Loads a few common JS/CSS assets in parallel with your app.
174-
- No liveboard data or API calls are made.
175-
- Minimal benefit (modern browsers cache these assets anyway).
176-
- Wastes bandwidth if the user never opens the embed.
184+
- Does not show Liveboard data or makes API calls
185+
- Offers minimal benefit because modern browsers cache these assets anyway
186+
- Results in unnecessary bandwidth consumption if the user never accesses the embedded content
187+
177188

178189
[NOTE]
179190
====
180191
Prefetch is generally not recommended unless you have a specific need, as modern browsers already cache static assets efficiently. Using prefetch may result in unnecessary network usage without significant performance gain.
181192
====
182193

183-
.Example: Prefetching assets
184-
[source,js]
194+
The following example shows how to prefetch assets:
195+
196+
[source,JavaScript]
185197
----
186198
import {
187199
prefetch,
@@ -204,16 +216,16 @@ image::./images/pre-render/preFetch.png[]
204216
== Strategy Comparison Table
205217

206218
[cols="1,1,1,1,1,1,2",options="header"]
207-
|===
208-
| Strategy | Loads in Parallel | Loads Data If Not Used | Loads Assets If Not Used | Reuses Iframe | Perceived Load Speed | Notes
219+
|====
220+
| Strategy | Loads in parallel | Loads data if not used | Loads assets if not used | Reuses iframe | Perceived load speed | Notes
209221
| Normal Render | ❌ | ✅ No | ✅ No | ❌ | ❌ Slowest | No reuse; re-renders every time
210222
| Prefetch | ✅ (few assets) | ✅ No | ⚠️ Yes (small assets) | ❌ | ⚠️ Slight improvement | Browser cache often makes it redundant
211223
| Prerender + ID | ✅ | ❌ Yes | ❌ Yes | ✅ | ✅✅✅ Fastest | Best UX, worst resource efficiency
212224
| Prerender w/o ID | ✅ | ✅ No | ⚠️ Yes (partial assets) | ✅ | ⚠️ Moderate | Trade-off between prep and efficiency
213225
| On Demand | ❌ | ✅ No | ✅ No | ✅ | ✅ (on revisit), ❌ (first visit) | Best balance of performance and efficiency
214-
|===
226+
|====
215227

216-
== How to Implement Pre-rendering
228+
== How to implement pre-rendering
217229

218230
You can use pre-rendering in both standard JavaScript and React. Here are the key methods and properties from the Visual Embed SDK:
219231

@@ -232,10 +244,10 @@ You can use pre-rendering in both standard JavaScript and React. Here are the ke
232244

233245
== Troubleshooting
234246

235-
* If the pre-rendered component does not appear, check that the container is visible and coordinates are set.
247+
* If the pre-rendered component does not appear, check whether the container is visible and coordinates are set.
236248
* Ensure you are not re-creating the embed instance on every render in React.
237249

238-
== Additional Resources
250+
== Additional resources
239251

240252
* link:https://github.com/thoughtspot/developer-examples/tree/main/visual-embed/pre-rendering[Pre-rendering examples on GitHub]
241253
* link:https://codesandbox.io/p/sandbox/github/thoughtspot/developer-examples/tree/main/visual-embed/pre-rendering[CodeSandbox: Pre-rendering]
-109 KB
Loading
-143 KB
Loading
-170 KB
Loading
-145 KB
Loading
-144 KB
Loading
-131 KB
Loading
-163 KB
Loading

0 commit comments

Comments
 (0)