-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use defer attribute on all script tags, remove inline JS #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm deploying the experimental `Feature-Policy` on my site. I tried disabling the `sync-script` policy, which blocks HTML-parse-blocking JavaScript, and django-debug-toolbar broke because its script tags aren't async or deferred. There's a bit more information about this feature, and a demo at https://feature-policy-demos.appspot.com/sync-script.html?on I've added `defer` to all the `<script>` tags, which makes them execute after HTML parsing has finished, in order. There was also one inline script for redirects which I've extracted - this would break for `sync-script` but also for use of `Content-Security-Policy` blocking inline JavaScript, which has been supported since django-commons#704 but it seems this was missed. Tested by using the `example` app, redirect interception worked and every panel loaded and looked right.
@graingert you added CSP and like security features, perhaps you'd like to check this? |
@@ -0,0 +1,3 @@ | |||
document.addEventListener('DOMContentLoaded', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be redundant with defer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idk how far back django-debug-toolbar tries to support, but ancient browsers don't support defer
, so best to leave it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://caniuse.com/#feat=script-defer goes back to IE6
Also the script tag is below the element so even if it fell back to sync it would work
@@ -0,0 +1,3 @@ | |||
document.addEventListener('DOMContentLoaded', function () { | |||
document.getElementById('redirect_to').focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is focussing a link not a form element :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang
Thanks! |
No worries, thanks for active maintenance! |
I'm deploying the experimental
Feature-Policy
on my site. I tried disabling thesync-script
policy, which blocks HTML-parse-blocking JavaScript, and django-debug-toolbar broke because its script tags aren't async or deferred.There's a bit more information about this feature, and a demo at https://feature-policy-demos.appspot.com/sync-script.html?on
I've added
defer
to all the<script>
tags, which makes them execute after HTML parsing has finished, in order. There was also one inline script for redirects which I've extracted - this would break forsync-script
but also for use ofContent-Security-Policy
blocking inline JavaScript, which has been supported since #704 but it seems this was missed.Tested by using the
example
app, redirect interception worked and every panel loaded and looked right.