Turbolinks 5: Add external javascript file from other site in a specific page Turbolinks 5: Add external javascript file from other site in a specific page ruby-on-rails ruby-on-rails

Turbolinks 5: Add external javascript file from other site in a specific page


Check out alphinejs. It was built for that purpose. According to the docs,

Alpine.js offers you the reactive and declarative nature of bigframeworks like Vue or React at a much lower cost. You get to keepyour DOM, and sprinkle in behavior as you see fit. Think of it likeTailwind for JavaScript.


Nowadays you can try stimulus.

It is born for page specific JavaScript sprinkles.

  • Add a new script tag like <%= javascript_pack_tag 'merchant' %>
  • In the merchant file, you can count on stimulus to handle event for turbolinks and jquery ready.

You can even use webpack and es6.

// hello_controller.jsimport { Controller } from "stimulus"export default class extends Controller {  static targets = [ "name", "output" ]  greet() {    this.outputTarget.textContent =      `Hello, ${this.nameTarget.value}!`  }}