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

Support lazy widget initialization within Marko Widgets #145

Open
shanimal opened this issue Jul 15, 2016 · 3 comments
Open

Support lazy widget initialization within Marko Widgets #145

shanimal opened this issue Jul 15, 2016 · 3 comments

Comments

@shanimal
Copy link

Looking for a modular approach to loading Marko widgets from the file server.

The thought is that some portions of your app may never be needed. Things like dialogs, detail views, shopping carts. It would make sense to not include those in the initial site load.

@patrick-steele-idem
Copy link
Contributor

Do you have any thoughts how this would look in practice based on your experience? Maybe some sample code to illustrate the pattern?

Also, are you using Lasso?

@shanimal
Copy link
Author

shanimal commented Jul 16, 2016

I'm thinking a lazy loaded widget would look exactly the same as a regular widget from the standpoint of template. If the application has a list of registered, properly name-spaced widgets, Marko would check the registry when it loads the template (i think it already does this) and if the widget doesn't exist, Marko would attempt to download it.

It might go something like:

  • check for the widget in the registry
  • if it doesn't exist check that lazy loading is enabled.
  • if the bundle is fully qualified on a x-domain, verify the bundle url with against a whitelist
  • if the bundle is relative get the default widget library endpoint
  • download and register the widget (JSONP on cross domains)
  • render the template or throw an error if it isn't found as usual

I'm assuming lasso could be used to bundle the components but it wouldn't be required.

Due to my lack of experience, the details of the implementation escapes me.

A dialog might look like this...
<alert-dialog-widget message="${data.error.message}" type="error" />

I'm assuming the widgets are properly bundled according to project needs. For instance a dialog bundle might include multiple widgets.
<alert-dialog-widget message="${data.error.message}" type="error" bundle="./dialog" />

But a widget located on a CDN might look like this
<widget-marko-cart bundle="http://marko-widget-cdn.org/components/shopping/">

Configuration could be passed of course
<widget-marko-cart bundle="${config.roots.shopping}">

@shanimal
Copy link
Author

One problem I've encountered in the past is optimizing so that you aren't loading code you already have. For instance we wouldn't need to include Marko and jQuery since we already have those.

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

No branches or pull requests

2 participants