2017 © Pedro Peláez
 

library slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

image

sankalp_sans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  • Thursday, March 1, 2018
  • by sankalpsans
  • Repository
  • 1 Watchers
  • 0 Stars
  • 822 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 3 % Grown

The README.md

slim-goes-slimmer

Released 2015.11.27, Updated 2024.03.18 (strip HTML comments), (*1)

HTML pages with embedded JS or complicated division hierarchy are written with indentation for readability and good developer experience. This causes websites' source codes to look like this:, (*2)

<html>
  <body>
    <div>
      <div>
        <span>
          <ul>
            <li>un
              <a>
                Some content here
              </a>
            </li>
            <li>
              <a>
                Some other here
              </a>
            </li>
            <li>
              <a>
                Still another content here
              </a>
            </li>
          </ul>
        </span>
      </div>
    </div>
    <script>
      function someAwesomeFunction() {
        // This function does something
        for() {
          if() {
           // Some code here
          } else {
           // Some more code here
          }
        }
      }
    </script>
  </body>
</html>

I did a rough benchmarking of this on several popular media websites and found that we waste somewhere from 20 to 30% of the HTML bandwidth to indented HTML and JavaScript. So, I decided to solve this problem, and implement this for Slim framework first, because this the framework I'm currently working with., (*3)

So far, slim-goes-slimmer reduces the above piece of HTML to, (*4)

<html>
<body>
<div>
<div>
<span>
<ul>
<li>
<a>
Some content here
</a>
</li>
<li>
<a>
Some other here
</a>
</li>
<li>
<a>
Still another content here
</a>
</li>
</ul>
</span>
</div>
</div>
<script>
function someAwesomeFunction() {
// This function does something
for() {
if() {
// Some code here
} else {
// Some more code here
}
}
}
</script>
</body>
</html>

... thus stripping whitespaces from the beginning of every line, (*5)

Why I haven't "optimized" it further?

Mainly because I'm facing weird issues with base64-encoded images in HTML, (*6)

Using

  • Just use composer require sankalp_sans/slim-goes-slimmer OR copy the file SlimGoesSlimmer.php to the relevant path and include it.
  • Register this to the Slim app object using
$app = new \Slim\Slim(...));
$app->add(new \Slim\Middleware\SlimGoesSlimmer());

Inspiration

This project is inspired by a project I have contributed to https://github.com/christianklisch/slim-minify earlier. I intended to contribute to it further, but haven't sone so because slim-goes-slimmer is specifically addresses to my set of problems, and I will tweak this as and how I need it on my PHP projects., (*7)

Results so far

Encouraging. I have been observing page sizes reduced by ~25% based on a sample of 100 pages, the list of which I will be publishing soon., (*8)

Contributing

Contributing is dumb simple. Fork, code, push and raise a pull request. I'll be happy if you could contribute test cases, as I usually am too lousy to code them., (*9)

The Versions

01/03 2018

dev-master

9999999-dev https://github.com/sankalpsans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  Sources   Download

MIT

The Requires

 

by Sankalp

php html minify

01/03 2018

v0.3

0.3.0.0 https://github.com/sankalpsans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  Sources   Download

MIT

The Requires

 

by Sankalp

php html minify

01/03 2018

dev-add-code-of-conduct-1

dev-add-code-of-conduct-1 https://github.com/sankalpsans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  Sources   Download

MIT

The Requires

 

by Sankalp

php html minify

27/11 2015

v0.2

0.2.0.0 https://github.com/sankalpsans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  Sources   Download

MIT

The Requires

 

by Sankalp

php html minify

27/11 2015

v0.1

0.1.0.0 https://github.com/sankalpsans/slim-goes-slimmer

Used to minimize the HTML output of Slim Framework in PHP

  Sources   Download

MIT

The Requires

 

by Sankalp

php html minify