简体   繁体   English

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

[英]What is better to do for a better performance?

I am showing the content of posts in my home page inside of div. 我在div中显示我主页中帖子的内容。 The div has a max-height property and overflow:hidden to keep it tidy just for case. div有一个max-height propertyoverflow:hidden以保持整洁只是为了大小写。

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 ? 用striptag显示所有内容并依赖于overflow:hidden的魔力overflow:hidden或使用substr也?

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. 但是,由于您将在页面生成时在内部检索整个帖子,因此除了必须检索完整文章的额外开销之外,您将节省很少的CPU /内存时间和一小部分带宽。

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 这里有一些来自cakephp的代码,可以在文本中处理html等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 ... 它可以比一个substr更复杂...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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