Help and documentation
Speed Low impact Medium 30–60 min
Inline scripts
Many <script>s directly in the HTML block and can't be cached.
What it is
Inline scripts are code directly in <script>…</script> in the HTML (not an external file). They block rendering at the point of occurrence and can't be cached or deferred via defer/async.
Why it matters
Large inline scripts inflate the HTML and block rendering. They also complicate the security policy (CSP).
How to do it
- 1Move the code into external .js files and load them with defer.
- 2Keep small essential initializations, but keep them minimal.
- 3Consider CSP, since inline scripts complicate it.
Conclusion
External files with defer usually beat inline scripts (cacheability + non-blocking). Move large inline blocks out; small initializations are fine. This is related to the overall strategy of deferring JS.
Related topics