title: Turbolinks unfriendly?
body: <p>I totally get why Turbolinks 5 is awesome and if you're reading it, you probably do as well, but I am very frustrated with how badly it plays with the other scripts on the block.</p>
  
  <p>To date, there is no simple explanation (human readable) that shows how to wrap existing jQuery scripts in a way that would allow them to function.
  Take for example this one: <a href="https://github.com/Bttstrp/bootstrap-switch" rel="nofollow noreferrer">https://github.com/Bttstrp/bootstrap-switch</a>. It's well written, simple to understand. You load the js and css to your assets pipeline and instantiate it on some page.</p>
  
  <pre><code># view.html.erb
  &lt;input type="checkbox" class="switch"&gt; switch button
  &lt;script type="text/javascript"&gt;
      $(".switch").bootstrapSwitch();
  &lt;/script&gt;
  </code></pre>
  
  <p>you go to view.html, click another page, click back and you see two buttons.</p>
  
  <p>Next, you spend 5 hours looking for a way to have Turbolinks load the instance of bootstrapSwitch only once if not loaded before. Well, even if you do, the functionality will be gone. Clicking it will not work.</p>
  
  <p><code>$(document).on("turbolinks:load", function()...</code> will load it on every Turbolink visit, and for now, the only way I could make it work and not create duplicates was to disable cache on view.html with</p>
  
  <pre><code>&lt;%= content_for :head do %&gt;
      &lt;meta name="turbolinks-cache-control" content="no-cache"&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Which feels kinda stupid.</p>
  
  <p>I think it all has something to do with using idempotent - <a href="https://github.com/turbolinks/turbolinks#making-transformations-idempotent" rel="nofollow noreferrer">https://github.com/turbolinks/turbolinks#making-transformations-idempotent</a> but how do you practically do this?</p>
  
  <p>Could someone please take this simple plugin as an example and share a simple, elegant solution for making it work which we can then reproduce with other scripts?</p>