summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/gold-weeks-hammer.md5
-rw-r--r--packages/astro/src/core/build/generate.ts3
-rw-r--r--packages/astro/test/redirects.test.js6
3 files changed, 14 insertions, 0 deletions
diff --git a/.changeset/gold-weeks-hammer.md b/.changeset/gold-weeks-hammer.md
new file mode 100644
index 000000000..4f6946116
--- /dev/null
+++ b/.changeset/gold-weeks-hammer.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Minify the HTML of the redicts emitted during the build.
diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts
index 5fe670e99..f1044434b 100644
--- a/packages/astro/src/core/build/generate.ts
+++ b/packages/astro/src/core/build/generate.ts
@@ -584,6 +584,9 @@ async function generatePath(pathname: string, gopts: GeneratePathOptions, pipeli
<body>
<a href="${location}">Redirecting from <code>${fromPath}</code> to <code>${location}</code></a>
</body>`;
+ if (pipeline.getConfig().compressHTML === true) {
+ body = body.replaceAll('\n', '');
+ }
// A dynamic redirect, set the location so that integrations know about it.
if (pageData.route.type !== 'redirect') {
pageData.route.redirect = location;
diff --git a/packages/astro/test/redirects.test.js b/packages/astro/test/redirects.test.js
index 17c1070dc..999ab1f0f 100644
--- a/packages/astro/test/redirects.test.js
+++ b/packages/astro/test/redirects.test.js
@@ -69,6 +69,7 @@ describe('Astro.redirect', () => {
root: './fixtures/ssr-redirect/',
output: 'static',
redirects: {
+ '/old': '/test',
'/': '/test',
'/one': '/test',
'/two': '/test',
@@ -82,6 +83,11 @@ describe('Astro.redirect', () => {
await fixture.build();
});
+ it("Minifies the HTML emitted when a page that doesn't exist is emitted", async () => {
+ const html = await fixture.readFile('/old/index.html');
+ expect(html).to.not.include('\n');
+ });
+
it('Includes the meta refresh tag in Astro.redirect pages', async () => {
const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('http-equiv="refresh');