简体   繁体   English

Zurb Foundation正在使我的资产加载两次

[英]Zurb Foundation is making my assets to load twice

application.css: application.css:

*= require_self
*= require foundation_and_overrides
*= require_tree .
*/

Application.js: application.js中:

*= require jquery
*= require jquery_ujs
*= require foundation
*= require jquery_nested_form
*= require highcharts/highcharts
*= require turbolinks
*= require_tree .
$(function(){ $(document).foundation(); });

Application.html.erb (generated by foundation): Application.html.erb(由基金会生成):

<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
  <head>
<meta charset="utf-8" />

<!-- Uncomment to make IE8 render like IE7 -->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=7" /> -->

<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>

<%= stylesheet_link_tag    "application" %>
<%= javascript_include_tag "vendor/custom.modernizr" %>
    <%= csrf_meta_tags %>
  </head>

  <body>

  <header>
    <nav class="top-bar">
    <%= render 'layouts/nav' %>
    </nav>
    <%= render 'layouts/flash' %>
  </header>

  <section>
    <%= yield %>
  </section>

  <footer>
    <%= render 'layouts/footer' %>
  </footer>


    <%= javascript_include_tag "application" %>
  </body>
</html>

development logs: 开发日志:

Started GET "/" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Processing by UsersController#show as HTML
Processing by UsersController#show as HTML
  Rendered users/show.html.erb within layouts/application (0.1ms)
  Rendered users/show.html.erb within layouts/application (0.1ms)
  Rendered layouts/nav/_director.html.erb (0.6ms)
  Rendered layouts/nav/_director.html.erb (0.6ms)
  Rendered layouts/nav/_manager.html.erb (0.4ms)
  Rendered layouts/nav/_manager.html.erb (0.4ms)
  Rendered layouts/nav/_supervisor.html.erb (0.2ms)
  Rendered layouts/nav/_supervisor.html.erb (0.2ms)
  Rendered layouts/_nav.html.erb (3.2ms)
  Rendered layouts/_nav.html.erb (3.2ms)
  Rendered layouts/_flash.html.erb (0.1ms)
  Rendered layouts/_flash.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 14ms (Views: 12.7ms | ActiveRecord: 0.3ms)
Completed 200 OK in 14ms (Views: 12.7ms | ActiveRecord: 0.3ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.alerts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.alerts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.dropdown.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.dropdown.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.forms.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.forms.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.joyride.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.joyride.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.clearing.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.clearing.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.magellan.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.magellan.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.orbit.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.orbit.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.reveal.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.reveal.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.section.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.section.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.cookie.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.cookie.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.topbar.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.topbar.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.interchange.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.interchange.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.tooltips.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.tooltips.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.placeholder.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.placeholder.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.abide.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.abide.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_nested_form.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_nested_form.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/index.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/index.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/highcharts/highcharts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/highcharts/highcharts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100

As you can see, it is loading each assets twice. 如您所见,它正在加载每个资产两次。 Furthermore, I am using nested_form , so when I click to add a nested form it adds many forms and not only one. 此外,我使用的是nested_form ,因此当我单击添加嵌套表单时,它会添加许多表单而不仅仅是一个表单。 However, if I refresh the page, the form works as expected. 但是,如果我刷新页面,表单将按预期工作。

I have tried to mode the <%= javascript_include_tag "application" %> to the top, but the nav menu does not work. 我试图将<%= javascript_include_tag "application" %>到顶部,但导航菜单不起作用。

Any idea? 任何想法?

To make your nav work properly, try adding gem 'jquery-turbolinks' to your Gemfile and then add //= require jquery.turbolinks to your application.js - that should take care of all the $(document).ready binds in the app. 要使导航正常工作,请尝试将Gemfile gem 'jquery-turbolinks'添加到您的Gemfile ,然后将//= require jquery.turbolinks添加到您的application.js中 - 这应该处理所有$(document).ready绑定应用程序。

Then move your javascript tag back to the head. 然后将您的javascript标记移回头部。

And, btw, it seems like the server is getting 2 simultaneous requests (eg from 2 livereloaded tabs in the browser), that could also be the case. 而且,顺便说一下,服务器似乎同时获得2个请求(例如,来自浏览器中的2个livereloaded标签),也可能是这种情况。

I had the same problem with double server logs, turns out it was an issue with the Rails STDOUT logger. 我遇到了双服务器日志的同样问题,原来这是Rails STDOUT记录器的一个问题。

Check out the following links: 查看以下链接:

A log that looks exactly like yours 一个看起来和你的完全一样的日志

Issue tracked here 问题在这里跟踪

Check your page request timeline with Chrome. 使用Chrome检查您的页面请求时间表。 If your page's assets are only loading once and getting logged twice this is most likely the same problem. 如果您的页面资产仅加载一次并且记录两次,则很可能是同一个问题。

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

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