为了获得更好的性能,最好做些什么?

I am showing the content of posts in my home page inside of div. The div has a max-height property and overflow:hidden to keep it tidy just for case.

My question is, what is faster/better? To show all the content with a striptag and rely to the magic of overflow:hidden or use a substr also ?

What's the intent of the overflow? To put in a "(show more)" type link? If that's the case, and you expect most users to want to read more, then output the full text and hide the excess.

If you expect most users to NOT want more, than output only the shortened snippet, and dynamically load the extra parts for the posts they do want the full text for.

However, since you'd be retrieving the entire post internally as the page generates anyways, you'd save very little in CPU/memory time and only a small bit in bandwidth, versus the extra overhead of having to retrieve full articles.

Substr is cleaner because you can add a suffix "..." to the text and also faster at loading and rendering at the first document loading.

here is a bit of code from cakephp that can handle html etc within the text https://github.com/cakephp/cakephp/blob/master/cake/libs/view/helpers/text.php#L183

it can get a bit more complex than a substr with ...