Proposal: Dynamic attrs #166
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Hi there. This isn't intended to be merged, but I'd like to start a discussion about it.
So I really like django-webpack-loader. However a limitation that I see are the static
attrs, ie. HTML attributes. They work fine for situations like async/defer etc., but there are more.When you look e.g. at the Content Security Policy spec (tldr: basically a host whitelist for your web app), you see different options to handle scripts, e.g. you can disallow inline scripts. But you can also configure CSP to allow inline scripts only when an attribute on them matches a random value ("nonce") from your server. (This is to be sure that it wasn't inserted by an attacker.)
Another situation would be Subresource Integrity, where instead of the nonce you use a checksum of the file. (This is to prevent your CDN from changing your code.)
Advanced usage of preload attributes could be another case where you'd want to have dynamic attributes. Anyways, I hope I convinced you by now.
As for this POC, it's not very pretty, but a start. It basically changes
attrsto be a template which gets rendered with the request context. This solves my first issue with the CSP nonce (from mozilla/django-csp). I'm not sure how one would implement dynamic attributes on a chunk (SRI from above) or request basis (e.g. "preload css only on home page"). If you would be inclined to give me some pointers and merge this in the end, I could continue working on it.Thanks for reading. What do you think?