Avoid Long Inline Scripts
ID |
html.long_inline_scripts |
Severity |
info |
Remediation Complexity |
low |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Html |
Tags |
code_smell |
Description
Flags an inline <script> (one with no src) whose body spans more lines than a small threshold.
Rationale
Large blocks of JavaScript embedded in the markup mix behaviour with structure, cannot be cached or minified independently, bloat every page that includes them and are awkward to test. A long inline script is a signal that the code belongs in an external, cacheable file.
<script>
// many lines of logic ...
// ... beyond the threshold
</script> <!-- FLAW — large inline script -->
<script src="app.js"></script> <!-- OK — external file -->
Remediation
Move the inline JavaScript into an external file and reference it with
<script src="…" defer></script>.