
Resolving the script tag type attribute hash prepending issue with Cloudflare
Fix Cloudflare\'s script tag hash prepending issue with our guide.
If your script HTML tag has the type attribute prepended with a hash, like <script type="ea10e272b0a1989fb2f3aa4e-text/javascript">...</script> and you’re using Cloudflare services, then the root cause is the Cloudflare Rocket Loader, a feature of Cloudflare that optimizes the loading of JavaScript resources on your web pages.
Rocket Loader modifies the type attribute of script tags for website loading optimization by deferring the loading of JavaScript until after rendering. This modification can cause issues with HTML validation and, when a Content Security Policy (CSP) is active, it requires CSP header updates. Cloudflare’s documentation states that if you have a CSP in place, you must update your headers to support Rocket Loader by adding ajax.cloudflare.com to the script-src directive. Without this, Rocket Loader will not function when a CSP is active.
Cloudflare Rocket Loader adds a type attribute to the script tag, causing issues with the W3C validator due to the “subtype missing” error. Cloudflare’s current Rocket Loader documentation acknowledges this as a known limitation: Some of Cloudflare’s optional features, including Rocket Loader and Email Obfuscation, use non standard tags that fail strict HTML validation via tools like w3.org. These failures do not correlate to issues for your site visitors.
Solution for hash prepending issue with Cloudflare
To resolve this issue, you have a few options:
- Disable Cloudflare Rocket Loader for specific paths: you can disable the Rocket Loader feature from Speed, Settings, Content Optimization in your Cloudflare dashboard. Disabling it site-wide will stop Cloudflare from modifying your script tags, including the prepending of a hash to the type attribute. For a more precise fix, use Configuration Rules to disable Rocket Loader only for specific hostnames or URL paths instead of turning it off for the entire zone.
- Use the
data-cfasync="false"attribute: by addingdata-cfasync="false"to your<script>tags, you instruct Cloudflare not to process these scripts with Rocket Loader.Thedata - cfasyncattribute must be placed before thesrcattribute for it to work. This can be a quick fix if you only have a few scripts that are causing issues. - Contact Cloudflare Support: if you’re unable to resolve the issue with the above steps, or if you need further assistance, you can contact Cloudflare Support through the Get More Help button in your Cloudflare dashboard.
Here’s an example of how to add the data-cfasync="false" attribute to a <script> HTML tag:
<script data-cfasync="false" src="your-script.js"></script>Compatibility warning for JavaScript module scripts
Recent community reports (2025–2026) show Rocket Loader breaking modern JavaScript module scripts. Rocket Loader rewrites type="module" scripts, which can break Vite SPA initialization. At least one developer documented migrating from a Vite SPA to static site generation (SSG) specifically to work around Rocket Loader’s interference with module scripts. If your site relies on type="module" scripts, test carefully with Rocket Loader enabled or exclude those scripts with data-cfasync="false".
Final notes
It’s important to note that while Rocket Loader can improve page load times by asynchronously loading JavaScript, it may also cause compatibility issues with certain scripts and affect HTML validation. Therefore, it’s essential to carefully evaluate the impact of Rocket Loader on your web pages and make adjustments as necessary to ensure proper functionality and compliance with web standards.
Comments