简体   繁体   中英

What is better to do for a better performance?

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更清晰,因为您可以在文本中添加后缀“...”,并且在第一次加载文档时加载和渲染速度更快。

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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM