question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mark endpoints as prerenderable

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, May 17, 2022

From #4942: we might also need a way to declare that an endpoint should never be prerendered (i.e. prerendering /foo doesn’t mean that /foo/__data.json is also prerendered, even though the data is inlined into the HTML)

2reactions
furudeancommented, May 17, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found