How do I load only certain js files from a specific html.erb? #339
-
I am a beginner. Since I am loading JS files from application.html.erb, I cannot load a specific JS file only in a specific html.erb. I am writing the JS in such a way that once there is an if statement in the JS, if there is a necessary element, the process will continue. Is there any way to load a specific JS only from a specific html.erb, like the general front writing style, like just before the body tag? Example |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi there! Although the guide uses tag helpers in For example, in <%= vite_javascript_tag "index" %> will render a script tag, which would load |
Beta Was this translation helpful? Give feedback.
Hi there!
Although the guide uses tag helpers in
application.html.erb
because that's the most common, you can instead use them inside views to load scripts as needed.For example, in
index.html.erb
:will render a script tag, which would load
entrypoints/index.js
.