I am building the site which seems fairly simple show data on page from database.
I want it to be as fast as possible. It already works/partially works in 3 ways:
#Approach 1
+page.server.js -> gets data from Supabase
+page.svelte -> gets data and creates a website
Advantages:
- works
- pre-fetch (hovering over links) works
Disadvantages:
- wasting a lot of time (100-600ms) waiting for document. I don't know what is the reason for waiting. Just render site (logo, menu, header etc.) and when data is retrieved show it on page. Don't make user wait with blank site for document to get downloaded. As stated in here: https://kit.svelte.dev/docs/load "Once all load functions have returned, the page is rendered." As said, it seems to be a waste of time to wait
#Approach 2
As stated in here: https://languageimperfect.com/2021/02/17/data-fetching-in-svelte.html
I only use +page.svelte with onMount
Advantages:
- works
- there is no wasted time waiting for document to retrieve data
Disadvantages:
- pre-fetch does not work
So in general this approach is faster for 1-st time user, however is much slower for desktop users (as there is no pre-fetch on hover)
#Approach 3
Only use +page.svelte, in <script context="module"> import data from Supabase and show it as:
{#await getDataFromSupabase}
<p>Loading ...</p>
{:then data}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
Advantages:
- there is no wasted time waiting for document to retrieve data
- pre-fetch works
Disadvantages:
- does not work with any additional parameters. For example I am not able to user page path to retrieve only selected data based on my URL
So those are my 3 ways already tested.
How to improve it?
My goal seems fairly simple:
1)Load data as soon as possible, without waiting for document (Approach #1 does not do it)
2)Pre-fetch should work, so if user hoover over link on desktop it should already start building webpage (Approach #2 does not do it)
3)I should be able to use parameters from URL (Approach #3 does not do it)
Any idea how to achieve it?
I've tried 3 methods described above. All 3 have some disadvantages.
I am looking for creating blazing fast webpage