Mark endpoints as prerenderable
See original GitHub issueDescribe the problem
If an endpoint loads data from the filesystem…
import fs from 'fs';
import marked from 'marked';
export function get({ params }) {
const markdown = fs.readFileSync(`content/${params.slug}.md`, 'utf-8');
return {
body: marked(markdown)
};
}
…then in most environments it will won’t work in production — it’s only suitable for prerendering. SvelteKit doesn’t know that, and will include the endpoint in the built app. This is bad for two reasons:
- it means deploying unnecessary code
- a mistyped URL will 500 instead of 404
We’re experiencing this right now with https://kit.svelte.dev/docs/nope.
Describe the proposed solution
If we could mark the endpoint with export const prerender = true, just like we do with pages, we could avoid including the endpoint in the deployed app.
The semantics are slightly different to export const prerender = true in pages, where it means ‘you can prerender this page’ as opposed to ‘you can ONLY prerender this endpoint’, but I think that’s probably fine.
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Kit is prerendering an endpoint on build, I feel like I have ...
The build script will prerender the endpoint. ... and prerender everything except pages that are explicitly marked as not prerenderable:.
Read more >Page options • Docs • SvelteKit
Pages not marked as prerenderable will be ignored and their links to other pages will not be crawled, even if some of them...
Read more >Connect your content to SvelteKit
... isn't marked as prerenderable (or is explicitly\n\t\t\u002F\u002F marked ... In this example, SvelteKit will run the code inside of endpoint route on ......
Read more >Mark endpoints and models as internal
Launched: Display endpoints and models in the order they appear in the OpenAPI ... A toggle in Studio to mark endpoints and models...
Read more >S-Index (NASA World Wind)
Schedule a task to mark a link as updated after a delay. ... intermediate positions between segments by interpolating the segment endpoints, or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

From #4942: we might also need a way to declare that an endpoint should never be prerendered (i.e. prerendering
/foodoesn’t mean that/foo/__data.jsonis also prerendered, even though the data is inlined into the HTML)This would be a huge performance boost for those managing content inside Svelte Kit (with e.g. MDSveX), where only a new build would actually require endpoints to update their content. Game changer for listing content, RSS feeds, sitemap, etc.