Skip to content

Commit

Permalink
Warn when loading Turbolinks from a <script> inside <body>
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Jan 4, 2018
1 parent 704a514 commit b99e541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/turbolinks/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#= require_self
#= require ./helpers
#= require ./controller
#= require ./script_warning
#= require ./start

@Turbolinks =
Expand Down
16 changes: 16 additions & 0 deletions src/turbolinks/script_warning.coffee
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

0 comments on commit b99e541

Please sign in to comment.