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 for lazy component imports #7

Open
FluffyDiscord opened this issue Sep 16, 2023 · 3 comments
Open

Support for lazy component imports #7

FluffyDiscord opened this issue Sep 16, 2023 · 3 comments

Comments

@FluffyDiscord
Copy link

dynamic() is really nice to make our code cleaner.

Yet it could be even better.

Right now every component inside dynamic loads at the same time when user visits the page. It would be nice to have them load on-demand, with lazy imports. The reason behind this feature request is that once your application grows and we have dozens of routes/pages, the browser then "downloads" all components at once and the initial page load can be longer, especially on mobile networks.

The lazy import should look like this (keep in mind the svelte:component needs to change too to something like this):

<svelte:component this={dynamic($path, [
  ['/', () => import('./Home.svelte')],
  ['/about',  () => import('./About.svelte')],
  ['/blog',  () => import('./Blog.svelte')],
  ['/blog/:post',  () => import('./Post.svelte'), {id: $params['post']}],
],  () => import('./Error.svelte'))} />
@howesteve
Copy link
Owner

howesteve commented Nov 16, 2023

Fair enough, I'll implement this in a future version. However, probably will have to be in a separate dynamicAsync() function or something like this.

@FluffyDiscord
Copy link
Author

Any updates on this?

@howesteve
Copy link
Owner

I intend to implement this in upcoming version 3.0 which will be svelte 5 compatible, as I mentioned in #8. I'll be closing this issue when I finish it.

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