diff --git a/.changeset/gold-weeks-hammer.md b/.changeset/gold-weeks-hammer.md new file mode 100644 index 000000000000..4f6946116649 --- /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 5fe670e99104..f1044434ba4a 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
Redirecting from${fromPath}
to ${location}
`;
+ 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 17c1070dc2ad..999ab1f0f3ed 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');