Feature #9759
openHTML minification and compression
0%
Description
To improve page loading, you can use Tidy for compressing HTML code (show source code of this example).
Yes the gain will be low, but this is a good start before to minify CSS and JavaScript files.
To further improve HTML compression, you can also gzip output.
Sorry, I don't know RUBY, but in PHP, you can gzip files with output buffering.
Related issues
Updated by Etienne Massip about 13 years ago
Rails 3.1 with sprockets enhance greatly serving of assets.
Updated by Daniel Felix almost 12 years ago
Well any news for this ticket?
It relates to Rails 3 support which is implemented. Currently redmine serves quite good and small source.
Updated by luigifab ! over 9 years ago
Hi all, I have done a beautiful code to GZIP (because Thin+lighttpd can't do this) and minify (with Tidy) HTML page!
In the application_controller.rb:
require 'base64'
...
class ApplicationController < ActionController::Base
...
after_filter :tidy
def tidy
if response.body =~ /<html/i
response.header['Content-Encoding'] = 'gzip'
response.body = `php /.../myfile.php #{Base64.encode64(response.body).gsub(/\n/, 'ø')}`
end
end
And my PHP file:
error_reporting(E_ALL);
ini_set('display_errors', 1);
$html = base64_decode(str_replace('ø', "\n", $argv[1]));
$html = str_replace('></option>', '> </option>', $html);
$html = str_replace('></button>', '> </button>', $html);
$html = myTidyFunction($html); // my custom function that call Tidy
$html = str_replace('> </option>', '></option>', $html);
$html = str_replace('> </button>', '></button>', $html);
$html = str_replace('<meta charset="utf-8"/>', '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>', $html);
$html = gzencode($html, 9, FORCE_GZIP);
echo $html;
Yeah, it's horrible!
But it works so very good.