Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
6 posts Page 1 of 1
Hi,

I was missing a HTML minifier feature, so I used the tiny-html-minifier from https://github.com/jenstornell/tiny-html-minifier
tiny-html-minifier.zip
(2.78 KiB) Downloaded 89 times

Installation:
  1. Download Add-On
  2. Extract directory `tiny-html-minifier` in 'couch/addons' folder.
  3. Add the following entry in 'couch/addons/kfunctions.php' file (if this file is not found, rename the kfunctions.example.php file to kfunctions.php)
    Code: Select all
    require_once( K_COUCH_DIR.'addons/tiny-html-minifier/TinyMinify.php' );
Usage
This addon makes available a new tag called minify. It is very simple to use:
Code: Select all
<cms:minify>
    <!-- here comes your HTML and CMS code :) -->
    <p>Compression works:</p>
    <ul>
        <li>
            Really?
        </li>
        <li>
            Really!
        </li>
    </ul>
</cms:minify>

Code will minified to:
Code: Select all
<p>Compression works:</p> <ul> <li> Really? </li> <li> Really! </li> </ul> 

You can set two additional parameter (collapse_whitespace and disable_comments) to true or false (default is false):
Code: Select all
<cms:minify collapse_whitespace="true" disable_comments="true"></cms:minify>


Requirements
PHP7+

Hope, you like and need it ;)
Awesome, will test this out! Thank you! Happy friday ;)
Very nice, SimonWpt. I have syntax-amended base class so it works on >=PHP 5.3 (minimal CouchCMS requirement).

Did you know that it is possible to auto-minify all HTML from both Admin Panel and Frontend automatically without using tags, using this addon and a couple of CouchCMS Events?
trendoman wrote: Very nice, SimonWpt.

Thank you and sorry for answering so late.
SimonWpt wrote:
trendoman wrote: Very nice, SimonWpt.

Thank you and sorry for answering so late.

No problem. Meanwhile I successfully deployed an addon that works for all pages automatically, but found that this TinyHtml library is not perfect and kills some js scripts, actually throwing parts of them completely. Doesn't work for admin panel as well because of improper handling of scripts. I had to disable it, unfortunately, and will look for alternatives. Not your fault, of course, I am only sharing my sad experience with this library.
Now addon's performance has been ingrained with most cms:tags in the form of parameter minify='1' (PM me if interested). It works just like tag-pair cms:minify (which is not required to be present) and requires a tiny bit less of code.
6 posts Page 1 of 1

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests