Skip to content

Commit 7f3c5ab

Browse files
committed
Merged PR 24012: preload api for embedding
preload api for embedding. user can give his embedUrl to "warm-start" the scripts, or uses a default reportEmbed url. This can run angular bootstrap & script downloading\parsing and utilize browser cache. This helps background loading as well as multi iframe scenario
1 parent 63cf0f0 commit 7f3c5ab

File tree

10 files changed

+88
-4
lines changed

10 files changed

+88
-4
lines changed

demo/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"es6-promise": "^3.2.2",
2121
"bootstrap": "^3.3.6",
2222
"jquery": "^3.1.0",
23-
"powerbi-client": "^2.2.1"
23+
"powerbi-client": "2.4.3"
2424
},
2525
"devDependencies": {}
2626
}

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"fetch": "^1.0.0",
3636
"http-server": "^0.9.0",
3737
"jquery": "^3.1.0",
38-
"powerbi-client": "^2.4.1",
38+
"powerbi-client": "2.4.3",
3939
"syntaxhighlighter": "4.0.1"
4040
},
4141
"devDependencies": {}

demo/v2-demo/scripts/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var anyReportSectionLoaded = false;
44

55
$(function() {
66
OpenSampleSection();
7+
WarmStartSampleReportEmbed();
78
});
89

910
function OpenSampleSection() {

demo/v2-demo/scripts/step_authorize.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ function OpenEmbedStepFromUserSettings() {
184184
OpenEmbedStep(EmbedViewMode, EntityType.Report);
185185
}
186186

187+
function WarmStartSampleReportEmbed() {
188+
FetchUrlIntoSession(reportUrl, false /* updateCurrentToken */).then((response) => {
189+
var embedUrl = GetParameterByName(SessionKeys.EmbedUrl);
190+
if (!embedUrl)
191+
{
192+
embedUrl = GetSession(SessionKeys.EmbedUrl);
193+
}
194+
const config= {
195+
type: 'report',
196+
embedUrl: embedUrl
197+
};
198+
199+
// Preload sample report
200+
powerbi.preload(config);
201+
});
202+
}
203+
187204
function setSession(accessToken, embedUrl, embedId, dashboardId)
188205
{
189206
SetSession(SessionKeys.AccessToken, accessToken);

dist/powerbi-client.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ declare module "service" {
943943
/** TODO: Look for way to make wpmp private. This is only public to allow stopping the wpmp in tests */
944944
wpmp: wpmp.WindowPostMessageProxy;
945945
private router;
946+
private static DefaultInitEmbedUrl;
946947
/**
947948
* Creates an instance of a Power BI Service.
948949
*
@@ -1039,6 +1040,15 @@ declare module "service" {
10391040
* @param {IEvent<any>} event
10401041
*/
10411042
private handleEvent(event);
1043+
/**
1044+
* API for warm starting powerbi embedded endpoints.
1045+
* Use this API to preload Power BI Embedded in the background.
1046+
*
1047+
* @public
1048+
* @param {embed.IEmbedConfigurationBase} [config={}]
1049+
* @param {HTMLElement} [element=undefined]
1050+
*/
1051+
preload(config: embed.IEmbedConfigurationBase, element?: HTMLElement): HTMLIFrameElement;
10421052
}
10431053
}
10441054
declare module "create" {

dist/powerbi.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.4.2",
3+
"version": "2.4.3",
44
"description": "JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and responding to data selection.",
55
"main": "dist/powerbi.js",
66
"typings": "dist/powerbi-client.d.ts",

src/service.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export class Service implements IService {
103103
wpmp: wpmp.WindowPostMessageProxy;
104104
private router: router.Router;
105105

106+
private static DefaultInitEmbedUrl: string = "http://app.powerbi.com/reportEmbed";
107+
106108
/**
107109
* Creates an instance of a Power BI Service.
108110
*
@@ -422,4 +424,32 @@ export class Service implements IService {
422424
utils.raiseCustomEvent(embed.element, event.name, value);
423425
}
424426
}
427+
428+
/**
429+
* API for warm starting powerbi embedded endpoints.
430+
* Use this API to preload Power BI Embedded in the background.
431+
*
432+
* @public
433+
* @param {embed.IEmbedConfigurationBase} [config={}]
434+
* @param {HTMLElement} [element=undefined]
435+
*/
436+
preload(config: embed.IEmbedConfigurationBase, element?: HTMLElement) {
437+
var iframeContent = document.createElement("iframe");
438+
iframeContent.setAttribute("style", "display:none;");
439+
iframeContent.setAttribute("src", config.embedUrl);
440+
iframeContent.setAttribute("scrolling", "no");
441+
iframeContent.setAttribute("allowfullscreen", "false");
442+
443+
var node = element;
444+
if (!node) {
445+
node = document.getElementsByTagName("body")[0];
446+
}
447+
448+
node.appendChild(iframeContent);
449+
iframeContent.onload = () => {
450+
utils.raiseCustomEvent(iframeContent, "preloaded", {});
451+
};
452+
453+
return iframeContent;
454+
}
425455
}

0 commit comments

Comments
 (0)