If you look at the HTML source of pages generated with CakePHP, you will probably detect a comment with the page execution time after the </html> tag that looks like:
<!-- 0.6885s -->
This comment is automatically added by Cake if the debug value in app/config/core.php is greater than 0.
As long as you only work with HTML in your views, this is no problem. But if you have to use a different format like JSON, you won’t love this comment and you have to get rid of it ;-)
There are two ways to accomplish this.
The first approach is to set the debug value to 0, for example in a single action, with:
Configure::write('debug', 0);
The other approach is to remove the code snippet which adds the comment with the page execution time. For this purpose open app/webroot/index.php, and at the end of the file remove the following code:
if (Configure::read() > 0) {
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
}
Happy baking!

I always use the method below in my app_controller.php
Hi,
I placed following snipped in my config/core.php
(still 1.1, but it`s simple to use it in 1.2)
Regards
Michał Bachowski
Hi,
I placed following snipped in my config/core.php
(still 1.1, but it`s simple to use it in 1.2)
Regards
Michał Bachowski
p.s. argh I forget about “code” tag - sorry :(
@Michał that’s very good idea, is it 100% effective?
The universal solution that’s always worked for me is to place a // at the end of your JavaScript/Ajax/JSON layout, like so:
<?php echo $content_for_layout; ?>//Simple, works in every scenario, no mucking with debug settings required.
Hi
@Abhimanyu: it works for me BUT - when you have an error somewhere around AJAX code you will not get any response (only standard Cake`s “404″ error page).
But solution posted by nate is even better than mine.
Thanks a lot nate :)
Regards
@all: Thanks for your comments!
@nate: Nice little trick!
What about writing this piece of code in beforeFilter, in app_controller:
if ($this->RequestHandler->isAjax()) {
Configure::write(’debug’, 0);
header(’Pragma: no-cache’);
header(’Cache-control: no-cache’);
header(”Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
}
what does nate’s “//” do?
Same question as @bfw. Not sure what “//” does??
// means the same thing in JavaScript as it does in PHP: ignore everything on that line that appears after it. So even though the timestamp comment is still printed, it is ignored by the JavaScript interpreter because it is after the //.
@Martin Bavio: btw, you can replace your header() calls with $this->disableCache();
Most simple solution, put the Configure::write(’debug’, 0) call in app/views/layouts/json/default.ctp.
Should not cause any problems since your json views should almost always be trivial (calling json_encode or $javascript->object()) or you might already be using the same trivial view for all of them.
@all: Thanks for your comments!
class DebugComponent extends Object {
function initialize(&$controller) {
if (!in_array($controller->params['url']['ext'], array(’htm’, ‘html’))) {
Configure::write(’debug’, 0);
}
}
}
@laowang: Thanks for sharing this component!
thanks! that helped!
@johnk: You are welcome :)