-
Notifications
You must be signed in to change notification settings - Fork 140
Express fragment dependencies? #121
Comments
If both the shell and foo fragments are synchronous then you don't need that require magic(def and undef) since the order of flushing them to the browser is guaranteed and requirejs takes care of the dependencies. I did try out the scenario you have specified here and it works without any issues, It will also work if you have specified the It will not work incase if the shell fragment is marked |
I though so as well, but I see two problems here:
So the require magic, which is controlled by the shell fragment, defines a named [1] https://github.com/zalando/tailor/blob/master/src/pipe.js#L65 (function (d) {
require(d);
var arr = ['react', 'react-dom', /* ... */];
while (i = arr.pop()) (function (dep) { define(dep, d, function (b) { return b[dep]; }) })(i);
}(['/base-assets/bundle.js'])); |
Regarding your concerns
But in your case, since you are defining the shell fragment through fragment html
If you do it via this way and if the other fragments like foo or whatever depends on this |
Thanks for the reply. Your last example is basically exactly how we solved it now, except that we also send the link header for Generally I really like the decision to let fragments not depend on each other. In our case, the shell fragment is a special snowflake :-) but we still decided to serve it as a regular fragment. We probably stick with our solution for now, just wanted to know if there was already a proven solution to solve said problem. From my side we can close the issue/question. [1] https://gist.github.com/jmaicher/f696b510008adadd94d2b7fbb35c8966#file-2-shell-fragment-html-L9 |
Yes as you mentioned, tailor looks for default init module from the fragment scripts and it was a requirement. Your solution will continue to work, But I would suggest you guys to put that script defining fragments to be in the head so that its loaded fast and user experience would be better. Thanks. Feel free top open the issue if you have more questions :) |
We have a shell fragment (header + sidebar) and one or many content fragments (mostly a single SPA). Our plan for the shell is to provide certain services to the content fragments via a client-side JavaScript API (e.g. to interact with the sidebar menu or the header search). For that to work, we somehow need to express fragment dependencies or ensure otherwise that the shell bundle is evaluated before any content fragment bundle.
Currently, we implemented this through RequireJS by letting the shell fragment define an AMD module inside of the fragment template, which depends on the shell bundle that is resolved via tailor. I outlined the solution in a gist [1].
Is there any better way to achieve this?
[1] https://gist.github.com/jmaicher/f696b510008adadd94d2b7fbb35c8966
The text was updated successfully, but these errors were encountered: