Lars282 Posted May 14, 2012 Share Posted May 14, 2012 Hey! Not sure the tile explains well what I am trying to do: For as long as I can remember, it seems to make a difference (when you care about every single pixel) whether you write <span>XX</span><span>XX</span><span>XX</span> or <span>XX</span> <span>XX</span> <span>XX</span> In this example there is an extra pixel of space between the spans. Now that most content is generated both manually and dynamically with PHP, this is an even bigger problem as there is no consistency. How can I get rid of this problem? I was thinking of somehow removing all tabs and line breaks from the delivered html file before displaying it to the user ... is that the best way and if so, how would I do that? Thanks a million and best wishes, Lars Link to comment Share on other sites More sharing options...
DaveP Posted May 14, 2012 Share Posted May 14, 2012 <?php $text = trim($text); $text = str_replace('\r', '', $text); $text = str_replace('\n', '', $text); ?> ...in various combinations will remove whitespace characters from the ends and <return> & <newline> from anywhere in $text. Link to comment Share on other sites More sharing options...
Lars282 Posted May 14, 2012 Author Share Posted May 14, 2012 Thanks! The problem is that the output comes not only from php code. There are various pieces hard coded without php, and then using <?= ... ?> to add content - so I cannot use your suggestion here. But when looping through children, the output comes from the php code, where I could ... but because it is php code with no line breaks manually added, it already is 'minified'. The question is how can I remove all the unneeded spaces/lines breaks/tabs from the file before displaying it to the visitor? What I am thinking: the pages are loaded through some processwire bootstrap index.php/module ... can that be modified to achieve what I want? Link to comment Share on other sites More sharing options...
Soma Posted May 14, 2012 Share Posted May 14, 2012 No, but you could create a module to $this->hookAfter("Page::render", $this, 'myrender'); into the Page::render and do it there. Edit: or use a ob_start() php method to buffer the output and do a callback that does the replacement. Link to comment Share on other sites More sharing options...
diogo Posted May 14, 2012 Share Posted May 14, 2012 You can also fight the spaces with other frontend techniques. I think this article might help you http://css-tricks.com/fighting-the-space-between-inline-block-elements/ Link to comment Share on other sites More sharing options...
ryan Posted May 14, 2012 Share Posted May 14, 2012 Now that most content is generated both manually and dynamically with PHP, this is an even bigger problem as there is no consistency. I'm not sure that I understand-- You should be in full control of your markup when you use ProcessWire, so whether you output with line breaks or not, or whatever you want your output style to be, is up to you. The only thing I can think of is perhaps TinyMCE? If so, I suppose that you could remove all whitespace between tags with something like this: $page->body = preg_replace('/>[\s\r\n]+</s', '><', $page->body); ...but I'd worry about unintended side effects, like situations where you really do want two tags on two lines. There is a purpose for whitespace in markup and it's probably not good to throw it out. But if you need to cover a specific situation, a regexp may be a good way to go. Link to comment Share on other sites More sharing options...
apeisa Posted May 14, 2012 Share Posted May 14, 2012 This might be interesting read for: http://css-tricks.com/fighting-the-space-between-inline-block-elements/ Link to comment Share on other sites More sharing options...
Soma Posted May 14, 2012 Share Posted May 14, 2012 This might be interesting read for: http://css-tricks.co...block-elements/ Aka two posts above. I also wonder what exactly the case is that would make it need something like this. I know about the issue, but never really had to fight with it. Can you provide examples (test page?), I'm sure it can be avoided somehow without php string replacments. Link to comment Share on other sites More sharing options...
apeisa Posted May 14, 2012 Share Posted May 14, 2012 Aka two posts above. Hehe, I read this from mobile and right when I got here I had to post that link - didn't notice Diogo's post there. Kertaus on opintojen äiti, as we say here (Repetitio mater studiorum as they use to say). Link to comment Share on other sites More sharing options...
Lars282 Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks guys! Link to comment Share on other sites More sharing options...
joe_g Posted March 9, 2014 Share Posted March 9, 2014 is there any server side solution to this ? Otherwise I should maybe try and write a module myself. All the client side solutions a pretty awful. I started using inline-block instead of float – much better, except for the space issue. j Link to comment Share on other sites More sharing options...
SiNNuT Posted March 9, 2014 Share Posted March 9, 2014 is there any server side solution to this ? Otherwise I should maybe try and write a module myself. All the client side solutions a pretty awful. I started using inline-block instead of float – much better, except for the space issue. j The http://modules.processwire.com/modules/all-in-one-minify/ does output minification. Use it myself a lot. If it suits your work-flow there's a lot more goodies you can use it for. 1 Link to comment Share on other sites More sharing options...
joe_g Posted March 9, 2014 Share Posted March 9, 2014 Perfect! thanks / bedankt! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now