Netcentric / aem-htl-style-guide

A style guide for the HTML Template Language (HTL), the templating language use by the Adobe Experience Manager (AEM).
MIT License
138 stars 50 forks source link

Add some rule about empty lines #14

Closed kwin closed 7 years ago

kwin commented 9 years ago

Currently the Sightly Compiler will never remove any blank lines from the HTML (see https://issues.apache.org/jira/browse/SLING-4443). That may lead to problems because a code like this

<sly data-sly-use="..." data-sly-unwrap />
<!DOCTYPE>

will lead to an output like this


<!DOCTYPE>

There is an empty first line being rendered by the Sightly script. One solution would be to always have the end tag of data-sly-unwrap elements at the beginning of the new line, so you would rather write it like this

<sly data-sly-use="..." data-sly-unwrap 
/><!DOCTYPE>
MikePfaff commented 9 years ago

I'd use a separate Sightly comment to actually make the newline part of the comment. Keeps the sly tag nicely on one line. Like we used to do with JSPs, using JSP comments to hide newlines from the output.

kwin commented 9 years ago

@MikePfaff Good idea, so the good example would then be

<sly data-sly-use="..." data-sly-unwrap /><!--/*
*/--><!DOCTYPE>

Still not nice, though, but the best we can currently do.

ErikGrijzen commented 9 years ago

This is for sure a big issue with Sightly, I totally agree.

I'm not 100% sure, but won't a HTML minifier be a better solution for this problems? I think there are implementation for JS and Java build automation. And I believe there are even server modules as well. What do you guys think?

If that won't solve the problem, I would definitely go for the comment solution. And only use it for parts that might give you actual problems. Because using this throughout your whole codebase is too messy in my opinion. And it's not worth it, because the HTML should get gzipped anyway. The difference is size will be very very small.

gabrielwalt commented 9 years ago

To @MikePfaff and @kwin: In the vast majority of cases, white spates in HTML have no functional impact and only are a question of esthetics. In the specific case of the Doctype, the W3C specifies that space characters are allowed before the doctype.

Therefore, it would be counter-productive to uglify the template, which is the core asset that we want to keep readable and maintainable, for changing the output a way that practically has no impact. If these spaces matter, e.g. to optimize the page speed, then you don't want to micro-optimize manually each line in the template, but you want to automatically solve this with an HTML minifier instead, as Erik suggests. Premature optimization is the root of all evil.

andreagriselli commented 8 years ago

Can we users expect a fix for this issue sometime in the near future? In some extreme cases you might end up with 7 or 8 blank lines in the generated html.

kwin commented 8 years ago

@andreagriselli This issue tracker is just about styling guidelines, but you are probably more interested in a flag in Sightly which prevents this. Use https://issues.apache.org/jira/browse/SLING-4443 to comment on that.

gabrielwalt commented 8 years ago

@andreagriselli, I think that the request is legit, but it should be more generally about a feature to optimize the HTML output of any script language (also JSP, etc). I'd file that request more generally than only related to HTL (aka Sightly).

AkankshaP commented 4 years ago

We are still seeing the issue of having blank lines in output HTMl. These lines are mostly due to conditional sly tags. Do we have any solution to it ?

kwin commented 4 years ago

Since there still is no flag in the HTL Compiler to remove those, the recommendation is to just ignore those. They should have no functional impact.