Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » HTML Minify

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2072 Views
  • Tonyair
    Avatar
    Community Member
    81 Posts

    HTML Minify Link to this post

    Hi guys, I have added HtmlMinify class to silverstripe, just open sapphire/core/HTTPResponse.php and replace line 199: echo $this->body with:

    line 199: require_once('thirdparty/minify/HTML.php');
    line 200: echo Minify_HTML::minify($this->body);

    Attached Files
  • cobianzo
    Avatar
    Community Member
    8 Posts

    Re: HTML Minify Link to this post

    just note that it's not
    sapphire/core/HTTPResponse.php
    but
    sapphire/core/control/HTTPResponse.php

    It would be great if this could be just a module, so we don't need to mess on the sapphire folder (and lose the changes when we update silverstripe).
    Also, this minify_HTML can bother a little for debugging purposes. I have set a flag to grab a GET parameter to deactivate it in case i want to see the code just as it is.

    However great class, thanks Tonyair.

  • cobianzo
    Avatar
    Community Member
    8 Posts

    Re: HTML Minify Link to this post

    Althought the change is working fine for the front end, this change in saphire generates an error when I "Save and publish" a page from the admin panel. I guess that it happens with some other actions. So I had to remove it.

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: HTML Minify Link to this post

    Hmmm ... thx ... i will fix it, just thought that i get such error cos of replacing TinyMCE with CKEditor.

    Upd.

    yep, it was pretty easy:

                if(!Director::isDev() && !Director::is_ajax()) {
                   require_once('thirdparty/minify/HTML.php');
                   echo Minify_HTML::minify($this->body);
                } else {
                   echo $this->body;
                }


    Extension of core modules in SilverStripe works a bit strange so i can't make it as module.

    Thank you for ur error reporting.
    I spend a lot of time trying to find out why with CKEditor I getting javascript parse error.
    Now everything is fine =)

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: HTML Minify Link to this post

    Tonyair, yes this is an interesting idea.

    I had to use HTML Tidy on SilverStripe for some sites, as there is a requirement from the client to make the HTML super neat. Your post makes me feel like to post that one I did.

    anyways I will look into your codes.

    @cobianzo I had that problem with HTMLTidy as well. it sometimes try to tidy everything which is a pain. What I did was to add some if conditionals to check whether they are viewing the site.

    on the page controller, init function I had a flag

    eg

    function init(){
    parent::init();
    $_REQUEST['RUN_HTML_TIDY'] = 1;
    }

    now on other places where you try to modify the output you can use

    if(isset($_REQUEST['RUN_HTML_TIDY'])){
    //// implement your code here.
    }

    2072 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.