Minify HTML with Flask-HTMLMIN

This commit is contained in:
Dave Page
2016-11-18 16:40:17 +00:00
parent d5351ad657
commit 020bf1d532
6 changed files with 6 additions and 19 deletions

View File

@@ -252,7 +252,6 @@ GOTO:EOF
ECHO Creating config_distro.py
ECHO SERVER_MODE = False > "%PGBUILDPATH%\web\config_distro.py"
ECHO HELP_PATH = '../../../docs/en_US/html/' >> "%PGBUILDPATH%\web\config_distro.py"
ECHO MINIFY_HTML = False >> "%PGBUILDPATH%\web\config_distro.py"
ECHO Building docs...
MKDIR "%PGBUILDPATH%\docs\en_US\html"

View File

@@ -157,7 +157,6 @@ _complete_bundle() {
cd "$BUILDROOT/$APP_BUNDLE_NAME/Contents/Resources/web"
rm -f pgadmin4.db config_local.*
echo "SERVER_MODE = False" > config_distro.py
echo "MINIFY_HTML = False" >> config_distro.py
echo "HELP_PATH = '../../../docs/en_US/html/'" >> config_distro.py
# Remove the .pyc files if any

View File

@@ -2,12 +2,12 @@ Babel==1.3
beautifulsoup4==4.4.1
blinker==1.3
click==6.6
django-htmlmin==0.8.0
extras==0.0.3
fixtures==2.0.0
Flask==0.11.1
Flask-Babel==0.11.1
Flask-Gravatar==0.4.2
Flask-HTMLmin==1.2
Flask-Login==0.3.2
Flask-Mail==0.9.1
Flask-Principal==0.4.0

View File

@@ -2,12 +2,12 @@ Babel==1.3
beautifulsoup4==4.4.1
blinker==1.3
click==6.6
django-htmlmin==0.8.0
extras==0.0.3
fixtures==2.0.0
Flask==0.11.1
Flask-Babel==0.11.1
Flask-Gravatar==0.4.2
Flask-HTMLmin==1.2
Flask-Login==0.3.2
Flask-Mail==0.9.1
Flask-Principal==0.4.0

View File

@@ -153,10 +153,7 @@ SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
# configuration databases 'keys' table and are auto-generated.
# Should HTML be minified on the fly when not in debug mode?
# Note: This is disabled by default as it will error when processing the
# docs. If the serving of docs is handled by an Apache HTTPD
# instance (rather than via the app), then it can be safely enabled.
MINIFY_HTML = False
MINIFY_PAGE = True
##########################################################################
# Server Connection Driver Settings

View File

@@ -20,7 +20,7 @@ from flask_login import user_logged_in
from flask_security import Security, SQLAlchemyUserDatastore
from flask_mail import Mail
from flask_security.utils import login_user
from htmlmin.minify import html_minify
from flask.ext.htmlmin import HTMLMIN
from pgadmin.utils import PgAdminModule, driver
from pgadmin.utils.session import create_session_interface
from werkzeug.local import LocalProxy
@@ -414,16 +414,8 @@ def create_app(app_name=config.APP_NAME):
##########################################################################
# Minify output
##########################################################################
@app.after_request
def response_minify(response):
"""Minify html response to decrease traffic"""
if config.MINIFY_HTML and not config.DEBUG:
if response.content_type == u'text/html; charset=utf-8':
response.set_data(
html_minify(response.get_data(as_text=True))
)
return response
if not config.DEBUG:
HTMLMIN(app)
@app.context_processor
def inject_blueprint():