sveltejs / sveltejs/kit

use ETags and browser cache to create memoized remote functions

Open
#14,794 3 comments 1 reaction 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

Because remote functions can't set headers I can't use ETag and the browser cache even when I'm certain the remote functions return value hasn't changed

Describe the proposed solution

offer a new type of remote function along with query, form, command and prerender

import { memo } from "$app/server"

export const getData = memo(async () => {
  const { etag } = getRequestEvent();

  if (dataStillFresh(etag)) {
    return // returns 304 Not Modified
  } else {
    let [etag, data] = getFreshDataAndToken()
    return [etag, data] // sets the ETag header
  }
})
Alternatives considered

The current alternative is to use load functions, which allow setting of the response headers.

Another alternative is to allow setting of response headers from remote functions.

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 with the remote functions entry point in $app/server and compare it with load functions, which the issue identifies as the current way to set response headers. Determine the scope of a memo remote function or header-setting alternative, including the requested ETag and 304 behavior; done should be defined by the chosen design and its browser-cache behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.