-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Improve the ScriptTagHelper to support CSP & ordered, async downloading inc. fallback #4817
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
Comments
@DamianEdwards I assume this isn't for RTW? |
Ya. |
Ideally, any possible solution that relies on inline scripts should discourage the use of the |
Allowing the user to specify the nonce via an attribute ( |
This is also an issue for the validation summary emitting |
Hi, What is the solution to validation summary emitting Thanks Mike |
Instead of document.write, could the tag helper emit document.body.insertAjacentHTML('beforeend', ... ) or similar, to allow the scenario where the script tag is contained within an Ajax response (e.g. when calling jQuery.load)? |
Let's handle this as part of our broader CSP story tracked by #6001 |
It appears our use of
document.write
in theScriptTagHelper
to dynamically load JS files in to the browser (the CDN fallback feature) causes issues when trying to use Content Security Policy.It appears this could be somewhat addressed by switching to dynamically creating and appending
script
elements to the DOM (assuming the CSP policy that enables inline script blocks is enabled), however that results in the scripts being loaded asynchronously to the page rendering, which potentially causes errors in the page (e.g. if the scripts now run out of order to how they were declared).This article is a good write-up of the various methods that can be used to load scripts while controlling (or not) their execution order and they're affect on rendering.
We should investigate whether we could enhance the
ScriptTagHelper
to better support these techniques, along with CSP, e.g.:async
attribute on thescript
element when dynamically loading the fallback script, maybe even use it as part of the download method toggle (always usedocument.write
unlessasync
attribute is explicitly set, or something)Possible example that would render inline JS to do async downloads of the scripts while preserving their declared execution order:
The text was updated successfully, but these errors were encountered: