vazco / universe-modules

Use ES6 / ES2015 modules in Meteor with SystemJS
https://atmospherejs.com/universe/modules
MIT License
52 stars 7 forks source link

Does this let me lazy load dynamic Blaze templates? #24

Closed skosch closed 9 years ago

skosch commented 9 years ago

The readme isn't very clear about how incremental loading of templates would work — this line:

System.import('finalComponent').then(function(module){

makes it look like downloading modules when needed is very much possible, but then lazy loading is explicitly listed as a Todo.

I'd be grateful if you could outline how exactly lazy loading would work, and, if there's still work to do, where I should start to experiment to this end.

MacRusher commented 9 years ago

You're mixing different things here :)

Right now all modules are bundled with rest of Meteor app, but are executed on demand (when you perform the import). So you execute them asynchronously, but they are ready to use at the moment you app code runs (usually, file order still matters and that is why you should perform first imports in main.js file that is executed last by Meteor).

We'll start working on lazy loading soon, and by lazy loading we mean that not all modules are going to be bundled with basic Meteor bundle. So you can skip downloading e.g. admin panel or other modules that are not used by majority of app users at initial load, and instead download them later on demand when you make the import statement.

Is this clear now? :)

As of Blaze, things get little tricky over here. When using React you can download and execute components at any time, but you cannot do the same with Blaze templates. You cannot easily add or modify templates once you pass the Meteor.startup phase. So you cannot lazy load and execute them later on demand. I'm afraid that lazy loading right now could be possible only for React, unless we find some hack that will allow us to do this is Blaze.

skosch commented 9 years ago

Thanks Maciek, the clarification helps. Yes, I'm talking about creating separate bundles, only a few of which will be downloaded initially.

Now, I'm dealing with 10K+ lines of Blaze code, so a rewrite in React isn't exactly something I'm looking forward to. Once lazy loading works in principle, would it work with a mix of React and Blaze (so that I can rewrite things slowly as I go along), or do I have to bite the bullet and rewrite everything at once? Hopefully that's something you can answer. Thanks!

MacRusher commented 9 years ago

Well you could have an app that uses both React and Blaze. We have an app that uses both so its possible, but IMHO it can get really messy :) So a gradual transition is possible if you want to switch to React.

We will try to provide lazy loading for Blaze templates, its just something that I cannot promise that we can deliver.

skosch commented 9 years ago

Awesome, thanks!