Skip to content

vite_javascript_tag in content rendered by UJS #100

Answered by ElMassimo
scmyers11 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Stephen!

Would you share a small example or repo where you are using this pattern with Webpacker?

The vite_javascript_tag renders a script tag—the only difference is that the script type is module.

Modules are only executed once, even if they have been referenced in multiple <script> tags.

For example, if you are relying on side-effects in the script but had previously imported it, the browser wouldn't execute it again the second time it's referenced.

HTML5 specifies that a <script> tag inserted with innerHTML should not execute.

Another reason for the script not executing would be the use of innerHTML to inject the script.


As @scmyers11 points out in the comment below, this seems…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@scmyers11
Comment options

@scmyers11
Comment options

@scmyers11
Comment options

@ElMassimo
Comment options

Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants