Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minify HTML?

Is there some tool (or Rails itself) that can minify HTML (like what Jammit does for CSS and JS files) ?

Secondarily, what is the best practice here, and is it even worth minifying the html? (this is for a site that will be served to mobile phones, so keeping weight down is important)

like image 478
Zabba Avatar asked Apr 24 '11 02:04

Zabba


People also ask

How do I minify HTML online?

Click on the URL button, Enter URL and Submit. Users can also minify HTML files by uploading the file. Minify HTML Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.

How do I minify HTML in Notepad ++?

Minify your code using Notepad++ Simply do the following: Edit > Blank Operations > Trim Header and Trailing Space. Edit > Blank Operations > Remove Unnecessary Blank and EOL.

Should I minify HTML?

Minification means to minimize code (HTML, CSS, JS) and markup in your web pages and script files. This reduces load times and bandwidth usage on websites. Moreover, it improves site speed and accessibility. Additionally, a user can access your website even with a limited data plan.


1 Answers

Well, you can remove most white space by using the HAML gem and the following lines in your config/application.rb file:

Haml.init_rails(binding)
Haml::Template.options[:format] = :html5
Haml::Template.options[:ugly] = true

More information: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ugly-option

like image 131
Josh Delsman Avatar answered Oct 12 '22 01:10

Josh Delsman