sveltejs / sveltejs/kit

Externalise scripts and styles when prerendering

Open
#3,555 1 comment 12 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

In certain situations it makes sense to externalise inline scripts and styles for CSP purposes (e.g. when building Chrome extensions).

Describe the proposed solution

This only really applies to prerendered pages (there's basically no good way to externalise a dynamically rendered script), so I propose the following interface:

// svelte.config.js
export default {
  kit: {
    prerender: {
      externalise: true
    }
  }
};

This would override the inlineStyleThreshold option. (If externalise isn't descriptive enough, we can bikeshed this.)

This would write out an inline script to the filesystem for each prerendered page, under the appDir (so the script can be cached immutably).

Alternatives considered

No response

Importance

nice to have

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

The issue does not name files, tests, or entry points. Start by locating the prerendering implementation and the handling of inline scripts and styles, then assess the proposed prerender.externalise option and its interaction with inlineStyleThreshold. Done means prerendered pages use external files under appDir while dynamically rendered scripts remain unaffected.

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
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.