Turbolinks不起作用-而是两次加载页面 [英] Turbolinks not working - instead loads page twice

查看:95
本文介绍了Turbolinks不起作用-而是两次加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我的Rails 4应用程序中,我具有Turbolinks gem.

So, in my Rails 4 app I have Turbolinks gem.

//= require jquery.js 
//= require jquery.turbolinks
//= require turbolinks

但是,似乎有些问题. Turbolink的意思是除了启动时不需要一次加载所有jquery/css/asset管道吗?好吧,这似乎没有发生,并且每次请求新页面时它都会继续加载所有jquery,而且,它甚至使每个页面加载两次.如:

However, something seems to be wrong. Isn't the point of Turbolinks that you don't have to load all the jquery/css/asset pipeline other than once at start? Well, that doesn't seem to happen, and it proceeds to load all jquery each time new page is requested, and what's more, it even makes each page load twice. Such as:

Started GET "/" for ip at 2014-01-21 18:55:35 +0200
*Loads bunch of stuff here*

Started GET "/" for ip at 2014-01-21 18:55:35 +0200
*Loads bunch of stuff here*

Started GET "/assets/jquery.js"
Started GET "/assetsjquery_ujs" 
Started GET "/assets/litecarousel"
Et cetera...

当我注释掉//= require turbolinks时,控制台似乎仅显示一页加载,这是正常的.可能是什么原因造成的?

When I comment out //= require turbolinks the console seems to show only one page load, which is normal. What could be the cause of this?

我有许多带有$(document).ready的jquery函数,但是有了 jquery.turbolinks ,这应该没问题.

I have many jquery functions with $(document).ready, but with jquery.turbolinks this should be just fine.

//测试了几件事,看来这是与Chrome相关的错误.在Firefox上运作良好.而且,我的gem版本是v.2.2.0.

// Tested out a few things and it seems it's a bug related to Chrome. Works good on Firefox. Also, my version of the gem is v.2.2.0.

推荐答案

您是否将<%= javascript_include_tag ... %>行放在页面的<body>标签之间而不是在<head>中?我曾经一次从Turbolinks收到各种奇怪的错误,这就是原因.

Have you put the line <%= javascript_include_tag ... %> between the <body> tags of your page instead of in the <head>? I was getting all kinds of weird errors from Turbolinks once and this was the cause.

这篇关于Turbolinks不起作用-而是两次加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆