Javascript Include Tag Best Practice in a Rails Application

后端 未结 4 2226
死守一世寂寞
死守一世寂寞 2020-12-12 11:50

Say I need to call a javascript file in the of an ERb template. My instinct is to do the usual:


<%= javascript_incl         


        
4条回答
  •  旧时难觅i
    2020-12-12 12:37

    I would suggest not to add javascript in the header as it causes to load the page slower. Rather load the js at the bottom of the page, which is faster. http://developer.yahoo.com/performance/rules.html#js_bottom

    
     ....
      <%= yield(:js) -%>
    
    

    And send it there from a view:

    <%- content_for(:js) do -%>
      <%= javascript_include_tag :defaults -%>
    <%- end -%>
    

提交回复
热议问题