Review main Merged

43747[FEATURE] Spaceless ViewHelper

Claus Due CR +2 V +2 Normal +147 −0 updated 10/07/15, 09:22

Commit message

Removes redundant spaces between HTML tags while
preserving the whitespace that may be inside HTML
tags. Trims the final result before output.

Heavily inspired by Twig's corresponding node type.

<code title="Usage of f:spaceless">
<f:spaceless>
<div>
    <div>
        <div>text

text</div>
    </div>
</div>
</f:spaceless>
</code>
<output>
<div><div><div>text

text</div></div></div>
</output>

Review

  • Code review CR +2
    • Benni Mack +2
    • Wouter Wolters +1
    • Frans Saris +1
  • Verified V +2
    • Benni Mack +2
    • Frans Saris +1

Issues 1

Files 3

Review log 17

  1. Claus Due uploaded patch set 1 10/02/15, 16:58

  2. Claus Due uploaded patch set 2 10/02/15, 17:02

  3. Claus Due uploaded patch set 3 10/02/15, 17:05

  4. Frans Saris commented on patch set 3 10/02/15, 18:04

    Doesn't this belong under f:format.spaceless also needs a rst file :)
  5. Christian Kuhn commented on patch set 3 10/02/15, 19:05

    nifty. i have seen the forge issue "hey, there is so much space now in my frontend with 'fluid styled content'" ... and since i roughly know how the fluid parser works it is obvious that the space problem can't easily be solved on an internal parser level. thus, i accept there is no different solution at the moment than having an "outer" view helper that parses out most white spaces with a regex after everything was rendered. main problem is here mostly that - if this VH goes amok for whatever reason and kills whitespaces where it shouldn't - the output may end up with a huge mess. i personally decided for me that i'd ignore the whitespace thing completely - for debugging we nowadays have browser internal inspectors, and when it comes to size i'd expect that every site that is actually concerned about size of transmitted data uses http compression anyway, the whitespace overhead will then shrink to nearly zero. still, for purists i can accept this additional VH and would support a merge. otoh, i would probably not use this VH within fluid styled content later by default since i mostly fear the regex parser overhead if a "huge" html result is parsed and this may result in additional server side time (and i actually fear a broken page in case the VH goes amok). if you want this VH later in fluid styled content by default, i'd expect some numbers to proof me wrong in this regard like "hey, forget it, this regex takes only half a millisecond to parse 2MB of html, this is acceptable".
  6. Claus Due commented on patch set 3 10/02/15, 21:25

    > Doesn't this belong under f:format.spaceless I don't think it does - it's more low-level than a mere formatter and should not be used as a formatter. It's more in the family of f:comment, imho. > also needs a rst file :) Fair enough :) I have no idea how to do that. > nifty. Thanks! > can't easily be solved on an internal parser level. thus, i accept there is no different solution at the moment than having an "outer" view helper Same conclusion I came to. > if this VH goes amok for whatever reason and kills whitespaces where it shouldn't - the output may end up with a huge mess. This pattern has not been a huge mess for Twig which has this very same helper. > i personally decided for me that i'd ignore the whitespace thing completely Same position I take, but the other use case is still quite valid. Fluid does produce a lot of extra whitespace. > otoh, i would probably not use this VH within fluid styled content later by default since i mostly fear the regex parser overhead if a "huge" html result It takes my machine 4.41 seconds to parse one gigabyte of HTML. It does so without any errors (according to simple validation with DOM). > this regex takes only half a millisecond to parse 2MB of html, this is acceptable". Probably takes a bit more than that, but a processing speed of one gigabyte in 4.41 seconds is extremely agreeable imho.
  7. Christian Kuhn commented on patch set 3 10/02/15, 22:54

    sounds good! a gigabyte isn't a real use case, though. "small" amounts of html would be more decent to measure. I'd personally expect something between maybe 100kb and max 10MB for a "casual" page. if the regex is below 1ms in those cases for a "casual" cpu, i'd be totally fine with adding this by default since this would be only a small amount compared to the overhead by other parts of the system in non-cached or user-int enabled requests (for full cached pages without user-int this is not calculated at all). Thus, it would be great to get an idea for real usecases. anyway, i'd be fine with adding a VH like this, adding it to 'fluid styled content' by default is a different patch anyway which may come along with some (real use case) numbers in the performance area.
  8. Claus Due commented on patch set 3 10/05/15, 11:06

    Thanks Christian - yes I agree, the fluid_styled_content change is another thing. It could be put in the Layout(s) and would cover. I'd estimate the performance numbers to be around 5 ms for a megabyte of HTML on a reasonably powered server, but you're of course welcome to verify this yourself.
  9. Frans Saris commented on patch set 3 10/06/15, 07:37

    Hi Claus you can find a help tool here https://forger.typo3.org/standard/rst for creating the rst file. Would love to see this in the LTS :)
  10. Claus Due uploaded patch set 4 10/06/15, 21:09

  11. Wouter Wolters commented on patch set 4 10/06/15, 21:14

    Feature-70170-ViewHelperToStripWhitespaceBetweenHTMLTags.rst:12

    one empty line after this.

    SpacelessViewHelper.php:7

    can we use our own header here and also in the test?
  12. Claus Due uploaded patch set 5 10/06/15, 21:25

  13. Claus Due commented on patch set 5 10/06/15, 21:28

    > can we use our own header here and also in the test? It wouldn't match any of the other class headers - also, https://review.typo3.org/#/c/42425/ changes all of them in bulk (and this ViewHelper is already part of standalone Fluid). Should I change it?
  14. Wouter Wolters commented on patch set 5 CR +1 10/06/15, 21:51

    can be changed later on IMO
  15. Frans Saris voted on patch set 5 CR +1 V +1 10/07/15, 07:16

  16. Benni Mack voted on patch set 5 CR +2 V +2 10/07/15, 09:22

  17. Benni Mack merged patch set 5 10/07/15, 09:22