sveltejs / sveltejs/kit

etags for `__data.json` requests

Open
#10,348 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

A few issues exposed by a dashboard with loads 2mb of data on a particular page.

  • SvelteKit will always call __data.json and doesn't do Conditional Requests / send eTags. 2mb. Every. Time.
  • Working around this limitation within Node via middleware, to implement eTags... why should we have to do this?
  • Data now loads twice, once for the page on first render, then again when the user clicks the back-button. Reloading the page is actually faster. We can use data-sveltekit-reload on links to the page and those are fast but the back-button is still slow by default (without the middleware)

I've debated call this a "bug" because I feel that SvelteKit, with all its clever tricks, should be better than the default behavior. Back button should not be slower than a page reload. It isn't expected behavior that going back to a page should yield different results. And even so, eTags are prevent data from being sent not re-computation. And middleware outside of SvelteKit shouldn't be necessary.

Describe the proposed solution

Some suggestions:

  • eTags for __data.json routes. If the data computes to the same hash, why send it again? Even with the invalidation flag, if nothing is changed there is zero reason to send all the data again. eTags aren't about saving computation but data transfer.
  • Offer some routes to just be SSR always, including back/forward button. The native behavior is sometimes just better and faster.
Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how SvelteKit handles __data.json requests, back/forward navigation, and the data-sveltekit-reload link behavior. Compare the proposed eTag conditional-request approach with an SSR-always route option; the work is done when one of these behaviors is defined and implemented without requiring external Node middleware.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
performance, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.