W3C validation fails due to CF

Cloudflare unfortunately modifies tags with invalid type tag.

Here is my original html:

<script src="js/myscript.js" type="text/javascript"></script>

Cloudflare, however, makes this into something like:

<script src="js/myscript.js" type="6e0e156949dd8b1694614bc1-text/javascript"></script>

The problem is that 6e0e156949dd8b1694614bc1-text/javascript is not a valid value for the type field. It should just be “text/javascript” as in the original html. In turn, W3C validation fails with an error:

Error: A script element with a src attribute must not have a type attribute whose value is anything other than the empty string, a JavaScript MIME type, or module.

Is it possible for Cloudflare to change the scripts to something like:

<script src="js/myscript.js" type="text/javascript" data-cf-someid="6e0e156949dd8b1694614bc1"></script>
instead?

In case you need to validate your HTML at http://validator.w3.org , kindly try disabling the “Rocket Loader” option at your Cloudflare dashboard.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Cloudflare unfortunately modifies tags with an invalid type tag.

Here is my original html :

<script src="js/myscript.js" type="text/javascript"></script>

Cloudflare, however, makes this into something like:

<script src="js/myscript.js" type="6e0e156949dd8b1694614bc1-text/javascript"></script>

The problem is that 6e0e156949dd8b1694614bc1-text/javascript is not a valid value for the type field. It should just be text/javascript as in the original html. In turn, W3C validation fails with an error:

Error: A script element with a src attribute must not have a type attribute whose value is anything other than the empty string, a JavaScript MIME type, or module.

I suggest that Cloudflare modifies the scripts to something like instead to confirm to W3C validation:

<script src="js/myscript.js" type="text/javascript" data-cf-someid="6e0e156949dd8b1694614bc1"></script>

Original post here: W3C validation fails due to CF - Developers - Cloudflare Community - but I did not receive a notification when posting / and the answer there suggest to disable Rocket loader - which is hardly the answer I am looking for.

Ping @simon

Unfortunately, that is not a sustainable solution. When search engines visit the site, we will get lower ranking because the html is invalid. Cloudflare must NOT produce invalid, non-compliant html.

I agree that Cloudflare should fix this. I turned Rocket Loader on yesterday. Now, every page on my site is not w3C compliant. Heading to turn it off now. Ridiculous.

I have to ask, because I really haven’t read that one before. You have some insights or official Google claim for that one?

(Although we do recommend using valid HTML, it’s not likely to be a factor in how Google crawls and indexes your site.)

Source:

For any invalid HTML code, you would get an report at Google Search Console to fix it. Either for SEO meaning (using JSON-LD, etc.).

As far as I use Cloudflare for enough time, haven’t had any error or specific one due to any invalid HTML because or the Rocket Loader at my Websites at Google Search Console.

I am afraid that in case you want to have W3C valid HTML (not CSS) Website, you would need to disable the Rocket Loader at Cloudflare dashboard.

Or, if there is a way to configure for specific user-agent that W3C HTML validation tool uses, to make Rocket Loader “skip” being enabled (not sure if possible)?

  • I remember there were some things to go around using PHP if{}..., but for some other stuff (not for Cloudflare)

From my perspective as a web enthusiast since being a 3rd grade of primary school, it doesn’t really matter if the Rocket Loader code doesn’t validate. Validation is only a guide, to warn you if there are potential problems in your code due to different presentation at different browsers and users.

You/we would end up at the same “invalidation HTML” even when we use Facebook code at our Website (be it tracking, be it comment/like box, etc.).

If you plan to speed up your website, and use Cloudflare’s Rocket Loader which just doesn’t validate as far for now, so if you are going to use it, you and all of us have to accept that one :slight_smile:

I believe there are no prizes for a clean validation, anyhow - or just having an W3C HTML valid logo?
The tool itself it’s just a way of checking if there are any major issues that may cause your page to break.

  • the other thing is if Rocket Loader conflicts with some other scripts and breaks your website …

Moreover, if concerned about SEO, validation of Javascript is not really an SEO issue.

There is also an video here (yes, 10 years old but …):

Don’t optimise for search engines - optimise for humans :wink:

3 Likes

Checking in here - the way the script tag is rendered is a necessary part of how Rocket Loader functions - there’s nothing we can do to change this - Rocket Loader needs to “hide” Javascript from the browser in this way, to prioritise the content loading over render-blocking Javascript.

I’m by no means an SEO expert but there’s lots of compelling content above from @fritex that explains that the validation concern is a non-issue.

That said, if you believe you’re receiving an SEO penalty (which seems to be undocumented/unproven) is more than the benefit of the increase in your page speed metrics that Rocket Loader provides, then your best option would be to disable in this case.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.