option to render layout before page is loaded
See original GitHub issueDescribe the problem
When building application-like websites, users expect instant feedback when changing pages, even if the page’s content isn’t ready yet. It’s confusing to a user when they click a button and nothing happens, then a second later the page changes. Loading indicators help but are still not ideal.
Describe the proposed solution
Provide an option that will allow a +layout.svelte file to be rendered before the +page.svelte is ready. For example, say clicking a button opens up a page that is a modal. We place the markup for the modal inside the +layout.svelte file and the content inside the +page.svelte file. As soon as the user clicks, we can render an empty modal. Then once the page is ready, the content will appear. While the page is loading, we can utilize the slot default as a loading page or skeleton UI.
<script>
// declare that this layout will be rendered to the DOM before the page is loaded
export const optimistic = true;
</script>
<div class="modal">
<slot>
<p>skeleton ui or loading indicator</p>
</slot>
</div>
Alternatives considered
- Using
#awaitblock so that surrounding markup is not dependent on data: This destroys SSR and sveltekit’s entire data model. - Having a dedicated
+loading.sveltefile: Seems like unnecessary complexity when it can be done without it. If for some reason someone requires separate default and placeholder page contents they can always use the$navigatingstore to switch between them.
Importance
would make my life easier
Additional Information
- If the
+layout.sveltealso relies on data we can still render it as soon as its own data is ready. - This probably shouldn’t affect SSR in any way. When we render on the server, we probably want to wait until the entire page is loaded before responding to the client. If we didn’t, it would defeat the purpose of SSR in the first place.
- As far as I know, this doesn’t break any existing functionality.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (8 by maintainers)

Top Related StackOverflow Question
The problem is that you can use
$page.dataanywhere on the page and if you access data from the page in a layout that would break. Something like+loading.svelteseems like a safer, more consistent solution to me.will point out that nextjs (which people will invariably compare sveltekit to) has
loading.jshttps://app-dir.vercel.app/loadingit appears to be the only major feature we lack in comparison