微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 性能问题:使用“link_to”还是“a”?

对于不需要太多控制器或选项的链接,使用html标签会更好吗?不必要地使用link_to rails标签会对性能产生任何影响吗?

谢谢.

解决方法

是.你可以在任何地方编写静态内容而不是动态内容,你会看到更好的性能.如果在特定情况下使用link_to使事情更易于编写和理解,那么使用它,但如果您自己认为没有必要,请节省cpu时间并自己编写标记.

这是专门讨论的,因为它与Rails助手in this article有关.根据文章

A number of helpers in Rails core will run rather slowly. In general,all helpers that take a URL hash will invoke the routing module to generate the shortest URL referencing the underlying controller action. This implies that several routes in the route file need to be examined,which is a costly process,most of the time… For pages displaying a large number of links,I have measured speed improvements up to 200% (given everything else has been optimized).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐