Adding defer attribute to inlined scripts has no effect. It only works here because modules are deferred by default.
Why don't you just add alpine import to index.ts and do component initialization there? Using this loader here makes no sense to me.
If you don't want to repeat initialization in every index.ts, you can do this in an inlined module:
Also, you're awaiting for alpine before starting components loading. You might start loading it in parallel and then continue component initialization when it's ready:
Adding
defer
attribute to inlined scripts has no effect. It only works here because modules are deferred by default.Why don't you just add alpine import to
index.ts
and do component initialization there? Using thisloader
here makes no sense to me.If you don't want to repeat initialization in every
index.ts
, you can do this in an inlined module:Also, you're
await
ing foralpine
before starting components loading. You might start loading it in parallel and then continue component initialization when it's ready:Hey @marzelin thanks for your observations.
How would you extend your code/solution to import modules when needed, e.g. on a click? I have seen lazy loaded import but how can I access alpinejs?
I think your second example code tries to do just that, but I get error in console:
loader.js:12 Uncaught (in promise) ReferenceError: alpinejs is not defined
at loader (loader.js:12:2)