Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1

It's me again nitpicking about a small but annoying thing.

If I add a few Couch tag lines like this:
Code: Select all
<cms:template title='Home' order='1'>
   <cms:editable name='main_image' label='Main image' type='image' />

When the page gets processed by couch before it's sent to the client browser it probably removes the tags meant for it. As a trace when for example the code up gets processed and the tags removed Couch leaves behind an empty line.

I usually put the template stuff in the beginning of the php document and now when Couch leaves behind empty lines there will be empty lines before the doctype if you look the source of the page. This isn't a big thing as most browsers will just skip the empty lines but also it isn't a good practice.

Is there a reason why Couch leaves an empty line when it removes the tags from the final source?

A line containing Couch tag usually also has a 'newline' at the end. Upon processing, Couch removes the tag but the newline remains. This is what is showing up as blank lines in the HTML output.

In a way, Couch is displaying 100% fidelity with respect to your markup - the newline was not a part of Couch's tag so it does not alter that at all.

I agree, it looks somewhat odd but is nothing to worry about at all (aesthetics apart) - HTML specs mandate all browsers to ignore whitespaces. Your outputted HTML will never fail W3C validation on account of these whitespaces.
Ok, this cleared things up. The remaining empty line is the new line pressed after the ending couch tag. It is doing it's job like it should but it feels odd to not parse the last line change as it usually is there because people start (or at least I start) a new line after the last couch tag.

I bet most people even leave an empty line between the ending couch tag and the next line. This results to two empty lines before the new line with content. Feels silly :p

Thanks for answering again!
Sorry for hijacking this old thread, but I have a closely related trick I want to share. In the current version of CouchCMS (1.4), you can open up /couch/cms.php and insert the following code before the block that begins on line 335 (i.e. before the comment // See if ouput needs to be cached)

Code: Select all
            $html = preg_replace('~>\s+<~', '><', $html);
            $html = preg_replace('<!--(?!<!)[^\[>].*?-->', '', $html);
            $html = str_replace('<>', '', $html);

This will remove all unnecessary whitespace and comments from your HTML output. It will leave conditional comments, style tag content, and embedded scripts intact. Basically, light minification.

Since CouchCMS leaves this extra whitespace, this trick can give (relatively speaking) a fair percentage of improvement, which should scale with your page length. For example, my short index page went from 9.4 kb to 7.5 kb after this change. Granted, these numbers don't account for the subsequent gzip compression, but hey, why not both? See this StackOverflow answer for more info.

Naturally, this trick is (probably) not worth it if you do not enable caching in /couch/config.php. I can't imagine that adding this computational overhead is good for your site's speed if you are re-generating the page for each request. Also, there are definitely other ways of doing this sort of minification. Perhaps you can compress the HTML in your *.php pages with grunt before they are processed by CouchCMS? I'm not sure. This way just seemed the easiest for me.

Lastly, making this change will not in any way alter the default <!-- Cached page served by CouchCMS - Simple Open-Source Content Management --> messages. (Nor the "generated by" messages.)

Edit: Wrong numbers, doh! Re-ran the before-after test. About 20% improvement, but in terms of the amount of data sent, it shouldn't be the first priority when optimizing.
@IllyaMoskvin thanks!
IllyaMoskvin please tell me tricks you offer really working?
Also ask - it is not it dangerous and Couch work you normally?

I'm not sure @IllyaMoskvin comes back to this thread.
I have tested this solution and it works, but is not ideal. For example it messes complicated comments in html, which consist of '--'. Example:

After applying this trick the following html comment will be partly seen on the frontend, because the structure will be different.
<!--All I want is a warm bed and a kind word and unlimited power. -- Ashleigh Brilliant-->
Will be reduced to the following, making this seen on frontend
< Ashleigh Brilliant-->
Just to inform - this behavior of the parser leaving behind whitespaces where Couch tags existed has been rectified in (coming up) v2.0. Now Couch tags behave exactly like PHP tags in this respect.
Looolll This is great - Thanks!
9 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