-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support immutable cache headers for _astro assets (#9125)
* Support immutable cache headers for _astro assets * Update .changeset/twelve-fishes-fail.md Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Update packages/integrations/node/src/http-server.ts * Update expected max-age * Add teh docs * Update .changeset/twelve-fishes-fail.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/integrations/node/README.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
- Loading branch information
1 parent
d90714f
commit 8f1d509
Showing
11 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/node': minor | ||
--- | ||
|
||
Automatically sets immutable cache headers for assets served from the `/_astro` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { expect } from 'chai'; | ||
import nodejs from '../dist/index.js'; | ||
import { loadFixture } from './test-utils.js'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
describe('Assets', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
let devPreview; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/image/', | ||
output: 'server', | ||
adapter: nodejs({ mode: 'standalone' }), | ||
vite: { | ||
build: { | ||
assetsInlineLimit: 0, | ||
} | ||
} | ||
}); | ||
await fixture.build(); | ||
devPreview = await fixture.preview(); | ||
}); | ||
|
||
after(async () => { | ||
await devPreview.stop(); | ||
}); | ||
|
||
it('Assets within the _astro folder should be given immutable headers', async () => { | ||
let response = await fixture.fetch('/text-file'); | ||
let cacheControl = response.headers.get('cache-control'); | ||
expect(cacheControl).to.equal(null); | ||
const html = await response.text(); | ||
const $ = cheerio.load(html); | ||
|
||
// Fetch the asset | ||
const fileURL = $('a').attr('href'); | ||
response = await fixture.fetch(fileURL); | ||
cacheControl = response.headers.get('cache-control'); | ||
expect(cacheControl).to.equal('public, max-age=31536000, immutable'); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/integrations/node/test/fixtures/image/src/assets/file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is a text file |
14 changes: 14 additions & 0 deletions
14
packages/integrations/node/test/fixtures/image/src/pages/text-file.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
import txt from '../assets/file.txt?url'; | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
<main> | ||
<a href={txt} download>Download text file</a> | ||
</main> | ||
</body> | ||
</html> |