Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

HTML Minify


Go to End


5 Posts   4514 Views

Avatar
Tonyair

Community Member, 81 Posts

25 September 2010 at 12:16am

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);

Avatar
cobianzo

Community Member, 8 Posts

11 October 2010 at 7:23am

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.

Avatar
cobianzo

Community Member, 8 Posts

11 October 2010 at 8:15am

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.

Avatar
Tonyair

Community Member, 81 Posts

11 November 2010 at 12:55am

Edited: 11/11/2010 1:15am

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 =)

Avatar
Nivanka

Community Member, 400 Posts

19 November 2010 at 1:40pm

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.
}