javascript css html minifier evaluation
Written: Jun-2023
HTML Code Minifier Discussion
Continuing on from evaluating the set of modules available for JavaScript minification, the need for HTML minification seemed another easy secondary solution that would help in reducing the noise being sent over the wire to the client browser. The evaluation was also more simple than the JavaScript - looking for (1) does it result in valid HTML, (2) does it remove block comments and (3) does it remove important block comments.
Class | Valid result | Block- comments | Minifies <style> contents | Minifies <script> contents | Removes CRs | Test speed** | Result size |
---|---|---|---|---|---|---|---|
JSqueeze | n | n | n | n | n | n | n |
Rodrigo54 | check | check | check1 | check1 | check | 0.0008 | 62.11% |
PHPClasses | check | check | close | close | check | 0.00062 | 65.78%2 |
JShrink | n | n | n | n | n | n | n |
PHPWee | n | n | n | n | n | n | n |
MatthiasMullie | n | n | n | n | n | n | n |
CSSTidy | n | n | n | n | n | n | n |
2 | This is computed based on the output without the <!DOCTYPE tag | ** | This will change and was simply a snapshot of the basic [small code] test run at one time. |
Scroll down, or click on the links in the table above to jump to the live-demo of each class involved.
Rodrigo54
https://gist.github.com
Code implementation is very simple:
rodrigo54-html.php
- Very easy deployment (note I decided to clipboard the raw-code into a Rodrigo54 class so that I could use it as an external class in my packages).
- Very simple and easy to understand code involving a set of regex's.
- Handles HTML and CSS as well as JavaScript, calling itself recursively when it detects
<style>...<
and/ style><script>...<
blocks./ script> - Removes comments and line breaks between tags
- Does what is says on the tin.
Cons
- No version number in the code or download, so you don't know if you're using older code.
PHPClasses
(package
Code implementation is very simple:
phpclasses-html.php
Pros
- It will remove line CRs
Cons
- Download requires a PHPClasses.org login before you can evaluate the solution.
- PHPClasses documentation and download area is a disaster and difficult to navigate.
- Strange use of .phpclass files (something I'm not familiar with).
- Documentation.
- No version number in the code or download, so you don't know if you're using older code.
- Not clear if any fixes have been applied to this code since first posting.
link Click to view a demo
square
chevron_leftjavascript-minifiers
css-minifierschevron_right