Skip to content

[docs] update html-minifier docs #3492

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

Merged
merged 2 commits into from
Jan 22, 2022
Merged

[docs] update html-minifier docs #3492

merged 2 commits into from
Jan 22, 2022

Conversation

benmccann
Copy link
Member

closes #3488

@benmccann benmccann added the documentation Improvements or additions to documentation label Jan 21, 2022
@changeset-bot
Copy link

changeset-bot bot commented Jan 21, 2022

⚠️ No Changeset found

Latest commit: 4d028c8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jan 21, 2022

✔️ Deploy Preview for kit-demo canceled.

🔨 Explore the source changes: 4d028c8

🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61ec0130c395f30008d7922d

@Rich-Harris
Copy link
Member

I kinda wonder if we should implement a transformPage option on resolve to handle this use case:

const response = await resolve(request, {
  transformPage: ({ html }) => minify(html, minification_options)
});

Creating a duplicate response feels a bit wasteful

@Conduitry
Copy link
Member

That feels like a little bit of a confusing and niche API for this. What would it get passed besides html? Would it only get called for text/html content? Would it let you do anything to modify headers or other content besides the body? This feels like a hook within a hook.

@benmccann
Copy link
Member Author

It is a bit verbose currently. I also wonder if it'd be a big niche to offer a helper. I do think if we were going to offer a helper it should allow you to override more than just the body such as:

cloneResponse(original, { status: newStatus, body: newBody, headers: newHeaders })

@Rich-Harris
Copy link
Member

It would be purely for manipulating rendered pages. This line...

const html = options.template({ head, body, assets });
...would become something like

const html = options.transformPage(options.template({ head, body, assets }));

There are other reasons you might want to manipulate the HTML, like replacing <html lang="%lang%"> with the current language (yes, Kit should provide first-class support for that anyway, but until it does...), plus probably others we haven't thought of. So it's not just scenario-solving

@Conduitry
Copy link
Member

We should merge this PR as-is anyway. I don't want to rush into an API for a new feature because it's holding up a fix in the docs about how the system currently works.

@Rich-Harris
Copy link
Member

I've opened #3511

@Rich-Harris Rich-Harris merged commit 1873156 into master Jan 22, 2022
@Rich-Harris Rich-Harris deleted the html-minifier-docs branch January 22, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The HTML minifier docs in the migration guide are out of date
3 participants