# A more efficient way to disable instant click with JavaScript?

**URL:** <https://discuss.hotwired.dev/t/a-more-efficient-way-to-disable-instant-click-with-javascript/5875>\
**Category:** General\
**Created:** [July 2, 2024, 4:18pm UTC](https://discuss.hotwired.dev/t/a-more-efficient-way-to-disable-instant-click-with-javascript/5875 "2024-07-02T16:18:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickjanetakis](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/nickjanetakis/32/2122_2.png) [@nickjanetakis](https://discuss.hotwired.dev/u/nickjanetakis)\
**Post date:** [July 2, 2024, 4:18pm UTC](https://discuss.hotwired.dev/t/a-more-efficient-way-to-disable-instant-click-with-javascript/5875/1 "2024-07-02T16:18:56Z")

</div>

Most of the time instant click / prefetching is useful but I’d like to disable it for all “copy to clipboard” links which is controlled through a single StimulusJS controller.

Instead of adding `data-turbo-prefetch="false"` to all of the links that copy something to your clipboard, you can add a `mouseover->clipboard#disablePrefetch` action to all of your links which would do `this.sourceTarget.parentNode.setAttribute("data-turbo-prefetch", false)` so that prefetching doesn’t happen. However, at this point if you have to go back and modify the links you might as well just add the prefetch false to each link.

That works fine, it’s all good but it involves going back to dozens of different ERB templates and adding that `mouseover` action or data attribute to all of the links.

I was wondering if this could be handled from the “other” side such as overriding the prefetch related code. Perhaps somewhere that lets you say “let this normal prefetch pass through except for when the link has a clipboard controller added to it”.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![walterdavis](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/walterdavis/32/737_2.png) [@walterdavis](https://discuss.hotwired.dev/u/walterdavis)\
**Post date:** [July 2, 2024, 4:45pm UTC](https://discuss.hotwired.dev/t/a-more-efficient-way-to-disable-instant-click-with-javascript/5875/2 "2024-07-02T16:45:12Z")

</div>

A trick I have used for other attributes (not this one particularly) is to add that attribute during the `connect()` method. Maybe try something like this in your clipboard controller (or any other that may be similarly impacted):

```auto
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {

  connect() {
    this.element.setAttribute('data-turbo-prefetch', false);
  }
  ...etc

```

See if that helps in your case (I haven’t tried it yet).

Walter

---

<div class="post-metadata">

**Author:** ![nickjanetakis](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/nickjanetakis/32/2122_2.png) [@nickjanetakis](https://discuss.hotwired.dev/u/nickjanetakis)\
**Post date:** [July 2, 2024, 6:28pm UTC](https://discuss.hotwired.dev/t/a-more-efficient-way-to-disable-instant-click-with-javascript/5875/3 "2024-07-02T18:28:52Z")

</div>

That’s a good idea and it works perfectly.
