I am building a fully static website with SvelteKit. I am using the @sveltejs/adapter-static version 3.0.5.
I want to load inside my webpage a simple table. For various compatibility and shareability reasons, I would like to store this table in a known data format like csv, json, parquet, etc.
First question: Considering the latest design of SvelteKit where should these files live?Should they live in the static
folder? Or in a top-level data
folder? Or in a $lib/data
folder?
Second question: Once I decided the best place to put these files, what is the intended/best way of loading these files?
My project structure follow the template skeleton:
src/├── app.html├── index.test.js├── lib│ ├── data│ │ └── data_1000.csv│ └── index.js└── routes ├──+layout.js ├──+page.js └──+page.svelte
The top of +page.svelte
looks like:
<script> /** @type {import('./$types').PageData} */ export let data;</script>
+layout.js
looks like:
export const prerender = true;
and +page.js
looks like:
/** @type {import('./$types').PageLoad} */export function load() { ...}
I tried using the fetch
API but I got errors related to not being able of using relative routes (I guess it is related to using a file system path instead of a URL) and I couldn't make the require fs
from the Node documentation to work.