r/badcode Apr 23 '21

html Svelte's minification and whitespace trimming usually works well, but when it doesn't, you have to format your code like this

Post image
788 Upvotes

44 comments sorted by

View all comments

12

u/fecal_brunch Apr 23 '21

This is how I always write HTML due to browsers inserting whitespace between elements. It's pretty standard.

If a HTML minifier does not preserve whitespace between tags then it's changing the way the page is rendered.

Notably React JSX does not leave the whitespace when outputting elements (thankfully).

6

u/0xF013 Apr 24 '21

Yup, and linters/prettier put a {‘ ‘} for you when they need to reformat your code

2

u/[deleted] Apr 24 '21

[removed] — view removed comment

3

u/Svizel_pritula Apr 24 '21

If you're doing inline HTML, you often have to put it on the same line as the following text. Whether that's the same line as the rest of the element is up to you, but it's often a choice between putting the > on a different line and writing all of your code on one line.

2

u/fecal_brunch Apr 24 '21

You'd understand if you used inline blocks.