Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Preload implementation #101

Closed
ramiroaisen opened this issue Apr 6, 2020 · 3 comments
Closed

Preload implementation #101

ramiroaisen opened this issue Apr 6, 2020 · 3 comments

Comments

@ramiroaisen
Copy link

i! very nice project,

I have an idea, that i will implement in a fork of this, but if your ok with it i'll make a PR.

The idea is that each component could export a preload function just like in sapper and then the router would first call preload to get the initial props

If its a promise the router will wait for it to resolve and then pass the props to the component instance

if the component doesnt export a preload function then the current behaviour is followed.

This way if components need to make extra fetch calls or something like that they dont have yo make a "loading" screen... or just blank screens between navigation

Also if this is implemented the router could prefetch preload calls in events like hovering over links and so like in sapper with <a href"#my-link' rel="prefetch"> or html

Tell me your thogths about that, and if you point me in the right direccion of where you think i can add this to your code i'll be pleased.

@hmmhmmhm
Copy link
Contributor

hmmhmmhm commented Apr 6, 2020

First of all, i think it is a very nice plan.
However, although the intention is good,
there are restrictions on browsers in the same way as above.

I remember that prefetch was able to operate
normally only if the exact file was named href.

If I remember correctly, just because the html file is referred to as prefetch does not
apply prefetch to all resources that are inductively used on that page.

And this router components are basically does not use code splitting.
(That means js files on all pages are loaded at once.)

Of coursely, The method of using code spliting and dynamic import is
described separately in Advanced Usage, but is not an essential method.

Even with the above methods, preload will be greatly influenced by Bundler.
I think this is a good idea, but I don't know how it would
be possible for the plug-in to interfere with the html.

If README.md should describe how prefetch is applied to
this router considering the user's performance,
I recommend adding the build script as follows.

https://github.com/hmmhmmhm/svelte-spa-template/blob/master/postbuild.ts#L52
https://github.com/hmmhmmhm/svelte-spa-template/blob/master/package.json#L15

@ItalyPaleAle
Copy link
Owner

Hey @ramiroaisen thanks for this suggestion. Would you be able to create a sample API to demonstrate this? That is: a sample of what kind of code you'd like to be able to write (not asking you to implement this, but just to show me what would be possible with it :) )

Is this just for asynchronous loading of routes like @hmmhmmhm describes?

@ItalyPaleAle
Copy link
Owner

This should be fixed by #73 in branch 3.0. Closing

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants