Is there a way around writing data: {turbolinks: false} a zillion times? Is turbolinks for rails worth it?

眉间皱痕 提交于 2019-12-02 11:53:51
Lanny Bose

So, the question you asked was "how to DRY up my endless link annotations?" I'll answer that, first...

Yes, if you turbolinks: false everything, then yes, you should just remove Turbolinks. Not because it's DRY, but because then you're disabling Turbolinks everywhere and might as well remove it. It doesn't do anything but deal with link-clicking.

If I can be so bold, though, I think your real question is:

"How do I get these cool jQuery plugins to work? I want them, and I never really asked for Turbolinks."

Without getting into specific plugins, many of them latch onto jQuery's $ function, which attaches to DOMContentLoaded. Turbolinks fires a different event instead (in Turbolinks-Classic this was the page:load event... in Turbolinks 5 it's the turbolinks:load event, that event isn't emitted and those event handlers don't get reset.

One possible answer for how to structure your JavaScript initializers is here.

I personally have stuck with Turbolinks, and as one last pitch, I'll point you towards Nate Berkopec's article 100ms to Glass with Rails and Turbolinks. He makes a reasonable case for why Turbolinks is a Good Thing.

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