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);
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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);
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.
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.
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;
}
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 =)
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.
}