Skip to content

Commit

Permalink
Preload the application assets and cache connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncomes committed Mar 26, 2024
1 parent 64ddc7b commit de010f1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example-embedded-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "https://github.com/prismatic-io/embedded.git"
},
"license": "MIT",
"version": "2.5.2",
"version": "2.6.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
21 changes: 20 additions & 1 deletion src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface InitProps
State,
"screenConfiguration" | "theme" | "fontConfiguration" | "translation"
>,
Partial<Pick<State, "filters" | "prismaticUrl">> {}
Partial<Pick<State, "filters" | "prismaticUrl" | "skipPreload">> {}

export const EMBEDDED_DEFAULTS = {
filters: {
Expand All @@ -34,6 +34,7 @@ export const EMBEDDED_DEFAULTS = {
marketplace: {},
initializing: {},
},
skipPreload: false,
theme: "LIGHT",
fontConfiguration: undefined,
translation: {},
Expand Down Expand Up @@ -62,6 +63,24 @@ export const init = (optionsBase?: InitProps) => {
return;
}

/**
* This establishes a connection to the prismatic url and preloads
* assets (css, js, fonts, etc.) into browser cache. Subsequent
* calls, use existing connections and cached assets.
*/
if (!options.skipPreload) {
document.body.insertAdjacentHTML(
"beforeend",
`<iframe
src="${state.prismaticUrl}/embedded"
title="PIO Embedded Preload"
height="0"
width="0"
style="visibility: hidden; display: none;"
/>`
);
}

document.head.insertAdjacentHTML("beforeend", styles);

const embeddedElement = document.createElement("div");
Expand Down
1 change: 1 addition & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface State {
embeddedDesignerEnabled: boolean;
prismaticUrl: string;
screenConfiguration?: ScreenConfiguration;
skipPreload?: boolean;
theme?: Theme;
fontConfiguration?: FontConfiguration;
translation?: Translation;
Expand Down

0 comments on commit de010f1

Please sign in to comment.