Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only cache content in /_app #1416

Merged
merged 19 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-files-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

Only cache files in /\_app/
15 changes: 9 additions & 6 deletions packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unresolved
import { getRawBody } from '@sveltejs/kit/node'; // eslint-disable-line import/no-unresolved
import compression from 'compression';
import fs from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import compression from 'compression';
import polka from 'polka';
import sirv from 'sirv';
import { getRawBody } from '@sveltejs/kit/node'; // eslint-disable-line import/no-unresolved
import '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unresolved
import { fileURLToPath } from 'url';

// App is a dynamic file built from the application layer.

Expand All @@ -29,8 +29,11 @@ export function createServer({ render }) {

const assets_handler = fs.existsSync(paths.assets)
? sirv(paths.assets, {
maxAge: 31536000,
immutable: true
setHeaders: (res, pathname, stats) => {
if (pathname.startsWith('/_app/')) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
res.setHeader('cache-control', 'public, max-age=31536000, immutable');
}
}
})
: noop_handler;

Expand Down