Web Developer, Python, Go
hamidfzm / flask-htmlmin Goto Github PK
View Code? Open in Web Editor NEWFlask HTML response minifier
License: Other
Flask HTML response minifier
License: Other
Web Developer, Python, Go
I don't know exactly why, but the example doesn't work in my environment. No minify output.
However your other answer works fine.
http://stackoverflow.com/a/26139704/564979
ty
Deprecated pytest-runner is not required for running the testsuite.
Hi. Getting a sporadic error 'unexpected call to parse_endtag". I haven't been able to replicate the issue reliably.
Occurs here in parse.py file in htmlmin.
assert rawdata[i:i+2] == "</", "unexpected call to parse_endtag"
However as a suggestion, perhaps a try except AssertionError should be added to the reponse_minify method. This way even if the error does occur, the final webpage is still rendered as the original unminified response is returned.
I'm testing the example provided in README:
from flask import Flask, render_template
from flask_htmlmin import HTMLMIN
app = Flask(__name__)
app.config['MINIFY_PAGE'] = True
htmlmin = HTMLMIN(app)
# or you can use HTMLMIN.init_app(app)
# pass additional parameters to htmlmin
# HTMLMIN(app, **kwargs)
@app.route('/')
def main():
# index.html will be minimized !!!
return render_template('index.html')
@app.route('/exempt')
@htmlmin.exempt
def exempted_route():
# index.html will be exempted and not blessed by holy htmlmin !!!
return render_template('index.html')
if __name__ == '__main__':
app.run()
And this is my templates/index.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<div>
Hello
</div>
<div>
World
</div>
</body>
</html>
I'm using python 3.7.2 and there is no minified output.
Flask-HTMLmin/flask_htmlmin.py
Line 32 in 82f828b
if you use flask.redirect, this redirection with code 302 and the response: https://github.com/pallets/werkzeug/blob/4397e61daf66ad43bd5668741c5d876de116a71f/werkzeug/utils.py#L373
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>Redirecting...</title>\n'
'<h1>Redirecting...</h1>\n'
'<p>You should be redirected automatically to target URL: '
'<a href="%s">%s</a>. If not click the link.'
for htmlmin.parser is not valid:
https://github.com/mankyd/htmlmin/blob/dff1163a1ec25fe94aeaeefe702377b5a9e912b3/htmlmin/parser.py#L261
that gives an error OpenTagNotFoundError()
Hi, thanks for the tool!
What do you think about allowing these settings to be set in the app.config?
default_options = {
'remove_comments': True,
'reduce_empty_attributes': True,
'remove_optional_attribute_quotes': False
}
default_options.update(kwargs)
As well as the other options for htmlmin from https://htmlmin.readthedocs.io/en/latest/reference.html?
Personally, I'd really like to add the "remove_empty_space". Somehow my output has whitespace between all tags, for example the closing tags on my homepage look like this -
</div> </div> </div> </body> </html>
Hello
Tried out the module .. ran into an error.
[2018-08-01 11:14:04 +0000] [2320] [INFO] Starting gunicorn 19.9.0
[2018-08-01 11:14:04 +0000] [2320] [INFO] Listening at: http://0.0.0.0:5000 (2320)
[2018-08-01 11:14:04 +0000] [2320] [INFO] Using worker: gevent
[2018-08-01 11:14:04 +0000] [2324] [INFO] Booting worker with pid: 2324
[2018-08-01 11:14:04 +0000] [2325] [INFO] Booting worker with pid: 2325
[2018-08-01 11:14:09 +0000] [2325] [ERROR] Error handling request /
Traceback (most recent call last):
File "/home/anon/miniconda2/lib/python2.7/site-packages/gunicorn/workers/base_async.py", line 56, in handle
self.handle_request(listener_name, req, client, addr)
File "/home/anon/miniconda2/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 160, in handle_request
addr)
File "/home/anon/miniconda2/lib/python2.7/site-packages/gunicorn/workers/base_async.py", line 107, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 2309, in call
return self.wsgi_app(environ, start_response)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 1833, in finalize_request
response = self.process_response(response)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask/app.py", line 2112, in process_response
response = handler(response)
File "/home/anon/miniconda2/lib/python2.7/site-packages/flask_htmlmin/init.py", line 35, in response_minify
self.html_minify.minify(response.get_data(as_text=True))
File "/home/anon/miniconda2/lib/python2.7/site-packages/werkzeug/wrappers.py", line 989, in get_data
rv = rv.decode(self.charset)
File "/home/anon/miniconda2/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: invalid start byte
Using the example I get this:
htmlmin = HTMLMIN(app, remove_comments=False, remove_empty_space=True, disable_css_min=True)
TypeError: unexpected keyword argument 'disable_css_min'
Also, when I install via pip, I get this: Using legacy setup.py install for Flask-HTMLmin, since package 'wheel' is not installed.
To help packagers, could you add LICENSE and README.md in tar for pipy ?
PyPI has 2.0.3 release but I don't see any new commits or tags on this GitHub project.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.