Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload the application assets and cache connections #75

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

jasoncomes
Copy link
Contributor

Issue:
We need a method to pre-load assets and connections when making calls within the embedded SDK.

Tried Solutions:

  • dns-prefetch: Unnecessary because DNS resolution to obtain the cached IP address has already been done.
  • preconnect: Establishing a preconnect from the top frame origin for resources referenced in the iframe will not function properly due to the differing origins between the top frame and the iframe.
  • preload: This method only preloads specified resources, which is ineffective for our case since our resources are bundled with different hashes. To make this work, we would need to create a remote-fetchable manifest that references these resources. This approach does not seem worthwhile.
  • prerender: Deprecating in Chrome and Edge, and already deprecated in Safari and Firefox.
  • prefetch: Only applicable for same-origin resources.

**Solution: **
Develop a publicly accessible embedded route which is initially blank but contains all the necessary assets (css, js, fonts, etc.) for caching. The connections are also shared among iframe origins. I confirmed that the assets are all the hashed the same, as you navigate the application.

Lifecycle of the Embedded:

  1. Begin the embedded process.
  2. Introduce a ghost iframe that directs to /embedded.
  3. Cache all assets in the browser to share them during future embedded SDK method calls.
  4. Share all connections for future embedded SDK method calls.

@jasoncomes jasoncomes force-pushed the jc/embedded-preload branch from 48417e9 to baabf8c Compare March 25, 2024 23:17
Copy link
Member

@taylorreece taylorreece left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once that endpoint is out; thanks! This'll really help load times on embedded marketplaces!

package.json Outdated Show resolved Hide resolved
src/lib/init.ts Outdated
* assets (css, js, fonts, etc.) into browser cache. Subsequent
* calls, use existing connections and cached assets.
*/
if (options.preload) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're making this configurable? Seems like it should just be the behavior of init

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it for possible performance issue from the consumer, although this isn't render blocking it does't it does defer the dispatch of the main pages on-load event until after its own on-load event is dispatched.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. If you think making this configurable is potentially helpful I'm game for it. However, optional properties with true defaults aren't ideal. Can you change this to skipPreload?: boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, doing now.

@jasoncomes jasoncomes force-pushed the jc/embedded-preload branch 2 times, most recently from c48fc6f to bc155cb Compare March 26, 2024 14:34
@jasoncomes jasoncomes force-pushed the jc/embedded-preload branch from bc155cb to de010f1 Compare March 26, 2024 14:39
@jasoncomes jasoncomes merged commit a0a3079 into main Mar 26, 2024
1 check passed
@jasoncomes jasoncomes deleted the jc/embedded-preload branch March 26, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants