forked from hotwired/turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when loading Turbolinks from a <script> inside <body>
- Loading branch information
1 parent
704a514
commit b99e541
Showing
2 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
do -> | ||
return unless element = script = document.currentScript | ||
return if script.hasAttribute("data-turbolinks-suppress-warning") | ||
|
||
while element = element.parentNode | ||
if element is document.body | ||
return console.warn """ | ||
You are loading Turbolinks from a <script> element inside the <body> element. This is probably not what you meant to do! | ||
Load your application’s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change. | ||
For more information, see: https://github.com/turbolinks/turbolinks#working-with-script-elements | ||
—— | ||
Suppress this warning by adding a `data-turbolinks-suppress-warning` attribute to: %s | ||
""", script.outerHTML |