Turbolinks not working - instead loads page twice

一世执手 提交于 2019-12-10 11:30:07

问题


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

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

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

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?

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

// EDIT: 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.


回答1:


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.



来源:https://stackoverflow.com/questions/21264809/turbolinks-not-working-instead-loads-page-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!