Is your feature request related to a problem? Please describe.
I am using the preload method for my static site to generate the navigation routes and download content from Contentful. Even though this code should run only on the server when the static site is generated, it is also is included in the client js.
Describe the solution you'd like
The preload method should only run on the server when exporting a static site and not be included in the client js.
Describe alternatives you've considered
There should be a seperate method where you can run code only on the server.
How important is this feature to you?
It is pretty important because I run code in preload which shouldn't be exposed to the internet. Also the bundle size would be smaller because the unused server code would be omitted from the client js.
The code in preload is needed on the client as well for when you are doing client-side navigation after the initial page load. If you have sensitive code, it should live in a server route, not a page route.
Alternatively, if you wrap code in if (!process.browser) {} it will be present only in the server bundle.
Thank you for your fast answer.
Sorry if I'm asking again, but isn't there a way to omit js which only generated the static html?
For example, the content of my index.html is generated from json on sapper export, but the html is rebuilt every preload. Also the json is included as a file (because of the server route) and also inlined in the index.html.
The problem is that the json/js is unnecessary because it is only run on the server on sapper export.
This would be something like SSR for dynamic components.
I ran into this as well - didn't really find a workaround
Most helpful comment
Thank you for your fast answer.
Sorry if I'm asking again, but isn't there a way to omit js which only generated the static html?
For example, the content of my index.html is generated from json on sapper export, but the html is rebuilt every preload. Also the json is included as a file (because of the server route) and also inlined in the index.html.
The problem is that the json/js is unnecessary because it is only run on the server on sapper export.
This would be something like SSR for dynamic components.