google / google/strict-csp

Feature Request: Automatically defer sourced scripts in the script loader

Open
#12 3 comments 1 reaction 0 assignees View on GitHub
feature
Dominant language
TypeScript
Stars
49
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Sourced scripts with `defer="true"` and/or `type="module"` are executed after the DOM has been parsed.

This behavior is ignored by default when the script is loaded dynamically. For this reason, a deferred script loaded through the CSP safe script loader will likely lead to issues: https://github.com/GoogleChrome/web.dev/pull/5008#discussion_r605203983.

I think it would be useful for this module to automatically implement the logic where deferred scripts are loaded on the `DOMContentLoaded` event, and also generate the preload links for those scripts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.