Project

General

Profile

Actions

Feature #9759

open

HTML minification and compression

Added by luigifab ! almost 13 years ago. Updated over 9 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

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

Related to Redmine - Feature #4796: Rails 3 supportClosedJean-Philippe Lang2010-02-10

Actions
Actions #1

Updated by Etienne Massip almost 13 years ago

Rails 3.1 with sprockets enhance greatly serving of assets.

Actions #2

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.

Actions #3

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>', '>&nbsp;</option>', $html);
$html = str_replace('></button>', '>&nbsp;</button>', $html);
$html = myTidyFunction($html); // my custom function that call Tidy
$html = str_replace('>&nbsp;</option>', '></option>', $html);
$html = str_replace('>&nbsp;</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.

Actions

Also available in: Atom PDF