Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

html_minify wraps result with unwanted '<html><head></head><body> ... </body></html>'

See original GitHub issue

Issue Description

I’m minifying a fragment of an HTML doc and html_minify prepends with <html><head></head><body> and appends a </body></html>, neither of which I want.

For example:

>>> from htmlmin.minify import html_minify
>>> html = 'boo'
>>> html_minify(html)

Is there a way to turn this behavior off?

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

moeffjucommented, Nov 26, 2013

wat. No it isn’t. Writing a HTML parser is HARD. Do you seriously think creating, let alone maintaining another one is realistic and smart?

Your problem is that html5lib (and BeautifulSoup) were made for the use case of documents. Fragments are not valid HTML documents, so they trigger automatic element insertion. On serialization, you get a complete (valid) HTML5 document. The question is why you are sending HTML fragments as text/html when your response is not a HTML document – just send a different Content-Type and you’ll be fine.

dev-codiyapacommented, Sep 13, 2018

Is there any solution for this ? I am getting same issues . So, it’s clear that it’s not fixed with current available version .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Google, Facebook and other websites minify their html?
Google, Facebook and many other sites are minifying their HTML by removing unnecessary white spaces and new lines from the HTML to send...
Read more >
Quickstart — htmlmin 0.1 documentation
Quickstart¶. For single invocations, there is the htmlmin.minify method. It takes input html as a string for its first argument and returns minified...
Read more >
html-minifier - npm
Minification comparison. How does HTMLMinifier compare to other solutions — HTML Minifier from Will Peavy (1st result in Google search for "html ......
Read more >
minify - Rust
extern crate minify; use minify::html::minify; fn main() { let html = r#" <html> <head> </head> <body> </body> <html> "#; let html_minified = minify(html);...
Read more >
How to Minify HTML in W3 Total Cache - BoldGrid
This is over a 50% reduction in total file size. Minify (default) should be your first choice for minifying your HTML, because it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found