1

I created a little page with sveltekit and tailwind css. Now I want to use the sveltejsadapter-static to create a complete static html version. This works fine for all subpages like /imprint or /privacy but the the first page / doesn't load the stylesheet.

Here's my svelte.config.js

import adapter from '@sveltejs/adapter-static';

const config = {
    kit: {
        adapter: adapter({
            pages: 'build',
            assets: 'build',
            fallback: null,
            precompress: false
        }),
        trailingSlash: 'always',
        prerender: {
            default: true
        }
    },
};

export default config;

By browsing to /imprint all styles look fine. The link to the stylesheet starts with /_app/…

When I load the base url, I can see the correct styles flashing for some milliseconds, but after that, all styles are gone. If I remove the / of the style and js links in the source code (_app/…), the page looks fine. But I can't find an option to create the first index file without the staring slash.

Also strange: When I click on the logo from /imprint (which links to /), the page looks fine, but never on first load.

2 Answers 2

1

Found the solution.

I defined the html tag in a component which is already defined in the app.html.

<svelte:head>
  <html lang="de" />
</svelte:head>
Sign up to request clarification or add additional context in comments.

1 Comment

Can you explain this more please? I'm having the same issue. But I don't quite understand your solution
0

Seems no one answers this, I'll just draft my experience and solution for this.

If you're using adapter-static + ssr + prerender, you can use onMount() or detect if loaded in browser before rendering the slot, this should solve the initial rendering.

// inside your +layout.svelte
<script>
    import { browser } from '$app/environment';
</script>

{#if browser}
    <slot />
{/if}

1 Comment

Would requiring JS to render the site half defeat the purpose of SSR by negatively impacting SEO?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.