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

“hugo --minify” strips spaces and preserve some new lines #6892

Closed
inwardmovement opened this issue Feb 13, 2020 · 19 comments
Closed

“hugo --minify” strips spaces and preserve some new lines #6892

inwardmovement opened this issue Feb 13, 2020 · 19 comments
Labels

Comments

@inwardmovement
Copy link

v0.64.1/extended windows/amd64

When I use hugo --minify in my branch/repo:

  • some new lines are not minified,
  • some spaces inside tags (that need to be preserved) are striped.

New lines not minified:
image
Space inside tag striped:
image
image

@aalfiann
Copy link

aalfiann commented Feb 24, 2020

yes me too, but this just happen on <a> tag only.

bep pushed a commit to bep/hugo that referenced this issue Mar 20, 2020
@bep bep mentioned this issue Mar 20, 2020
bep pushed a commit to bep/hugo that referenced this issue Mar 20, 2020
bep pushed a commit that referenced this issue Mar 20, 2020
@tdewolff
Copy link

I want to clarify that "newlines are not minified" is incorrect. The minifier removes superfluous whitespace, but sometimes whitespace in HTML has meaning and cannot be removed. In that case either a space or a newline are required, and both have the same effect. The minifier will let the remaining significant whitespace be a newline when any of the original whitespace characters contained a newline. This newline cannot be removed without changing the display of HTML.

You second issue that whitespaces get remove in tags, this is because you use the CSS white-space property or you change display to inline. This changes the semantical meaning of HTML and may influence layouts that depend on whitespace for formatting. It is not recommended to let your HTML layout depend on whitespace!

@bep
Copy link
Member

bep commented Mar 20, 2020

@tdewolff thanks for the input and your work on this, much appreciated. I have not looked into this particular issue, but we just merged way to configure and turn off a given minified, so that should solve most of these issues.

@virgofx
Copy link
Contributor

virgofx commented Apr 12, 2020

@tdewolff Just a minify note. It appears that the first nested <source> block inside a <picture> element, preserves the newlines between the parent picture and first source element. I don't see why they should be preserved.

image

Untitled-2

@tdewolff
Copy link

Thanks for that! I've fixed it in tdewolff/minify@8a5c9ca. Seems that both audio and picture could remove their initial space. Make sure you have KeepWhitespace = false!

@virgofx
Copy link
Contributor

virgofx commented Apr 14, 2020

Thanks @tdewolff . Will wait for @bep to let us know what version this is updated in.

@virgofx
Copy link
Contributor

virgofx commented Apr 23, 2020

@tdewolff Any chance you can cut a new release so master branch changes can be leveraged?

@bep any chance we can get an updated build with latest tdewolff/minify version?

@tdewolff
Copy link

Will push one out soon, I'm very busy with work these weeks unfortunately :-( sorry about that

@bep
Copy link
Member

bep commented Apr 23, 2020

@virgofx I had to revert to an older version of that library some time ago as it broke many sites in the wild. So we're currently a little behind.

@tdewolff
Copy link

I've pushed out 2.7.4

@bugsysailor
Copy link

I too have had issues with spaces being remove, and the other thing I noticed with hugo --minify is that these select list options are not minified which I found interesting.

Screen Shot 2020-04-29 at 5 16 49 PM

@tdewolff
Copy link

Thanks @bugsysailor, fixed your issue in tdewolff/minify@7d9c460

Please remember that Hugo prevents removal of end tags. The default settings of the minifier will remove all superfluous </option> end tags. Let me know if you hit any other tips!

@DannyJJK
Copy link

Is there any way to get rid of the new lines with the current config settings? I've set all the "Keep…" options to false, although I still get new lines. My HTML/CSS is set up in such a way where it doesn't rely on whitespace so they aren't needed

@tdewolff
Copy link

Some whitespace is significant in HTML, that whitespace character may be a space or a newline (both are 1 byte long). Eventhough your file contains newlines it may not be possible to further minify its contents.

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 25, 2020
@tiagoboldt
Copy link

This issue has been marked as stale, but I am still experiencing this behavior with hugo 0.80.

@stale stale bot removed the Stale label Jan 29, 2021
@DannyJJK
Copy link

DannyJJK commented Jan 29, 2021

I still experience this as well, although I understand why it works like it does. I think what's needed is an option to disable the whitespace generated by newlines in the code. If I have:

<a href='url'>Link 1</a>
<a href='url'>Link 2</a>
<a href='url'>Link 3</a>

in my HTML, I'm not saying I want a space between each HTML tag even if it appears that way on the page when there's no stylesheet, the newline generates whitespace that I don't want and I visually remove it with CSS. I would like an option for these tags to be on one line when minified with no whitespace between them.

@jmooring
Copy link
Member

With the various comments since this issue was originally created, the scope and detail are no longer clear. It contains unrelated reports of problems and suggested changes.

We bumped tdewolff/minify to the most current version (v2.9.15) with Hugo v0.82. Please test to see if your problem or enhancement has been addressed, and create new specific issues as needed.

Please remember that minification has a number of configuration options:
https://gohugo.io/getting-started/configuration/#configure-minify

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants