Search code examples
javascriptsveltesveltekit

How to detect whether script was loaded client side or server side in Svelte?


How do I detect whether a script was loaded from +page.server.js or +page.svelte?

Is there a (Svelte) function that I can import to see the difference?


Solution

  • There is a browser flag you can check:

    import { browser } from '$app/environment';