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
Hello, do you have any examples of preloading JSON
The text was updated successfully, but these errors were encountered:
Hi there @suyizhang thanks for asking.
You should be able to do something like this:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Load JSON Example</title> <link href="style.css" rel="stylesheet" /> <link rel="preload" href="data.json" as="fetch" /> </head> <body> <h1>Loading JSON Example</h1> <script> async function loadData() { try { const res = await fetch("data.json"); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } loadData(); </script> </body> </html>
Which assumes that you have these resources:
├── data.json ├── index.html └── style.css
Does that answer the question?
Closing for the moment as I think the question is answered
Hello, do you have any examples of preloading JSON
The text was updated successfully, but these errors were encountered: