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

相关文章
相关标签/搜索