[英]Zurb Foundation is making my assets to load twice
application.css:
*= require_self
*= require foundation_and_overrides
*= require_tree .
*/
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(由基金會生成):
<!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>
開發日志:
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
如您所見,它正在加載每個資產兩次。 此外,我使用的是nested_form
,因此當我單擊添加嵌套表單時,它會添加許多表單而不僅僅是一個表單。 但是,如果我刷新頁面,表單將按預期工作。
我試圖將<%= javascript_include_tag "application" %>
到頂部,但導航菜單不起作用。
任何想法?
要使導航正常工作,請嘗試將Gemfile
gem 'jquery-turbolinks'
添加到您的Gemfile
,然后將//= require jquery.turbolinks
添加到您的application.js中 - 這應該處理所有$(document).ready綁定應用程序。
然后將您的javascript標記移回頭部。
而且,順便說一下,服務器似乎同時獲得2個請求(例如,來自瀏覽器中的2個livereloaded標簽),也可能是這種情況。
我遇到了雙服務器日志的同樣問題,原來這是Rails STDOUT記錄器的一個問題。
查看以下鏈接:
使用Chrome檢查您的頁面請求時間表。 如果您的頁面資產僅加載一次並且記錄兩次,則很可能是同一個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.