Script tags added outside of html

When a page contains too much characters, the Cloudflare scripts are added after the closing html tag, and then the browser does not load them.
For analytics script this means missed analytics, for the rocket loader script this means a broken site.

As links are not allowed I cannot add an example, but the page source is:

...
</body>
</html>


<script defer src="https://static.cloudflareinsights.com/beacon.min.js/v ...

May I ask have you tried disabling some features at Cloudflare dashboard like:

  1. Auto Minify options
  2. Rocket Loader

Therefore, using “Purge Everything” to flush the cache at Cloudflare and double-checking this using a different Web browser? :thinking:

I wonder, if you temporary use “Pause Cloudflare for this site” option from the bottom-right corner at the CF dashboard → Overview tab, is your HTML code valid and are all the HTML tags properly closed? :thinking:

Hi @fritex , thanks for your response. I am replying in behalf of Silvan, we are both checking this issue.
I have disabled “Automatic Platform Optimization for WordPress” and “Auto Minify” (Javascripts, CSS and HTML). Rocket Loader was not enabled (we have APO).
I purged cache, and the issue remains.

About the other test, I configured my hosts file to point directly to backend server and got a direct html response without Cloudflare man in the middle. The html I got is valid, no major issues, no unclosed tags.

Html for this page is quite big, we think this could be the reason why Cloudflare is failing to parse it correctly. Is there a limit on the size?

Thanks.

1 Like

Thank you for feedback information.

Interesting :thinking: I have checked and on each website I manage and maintain, the beacon script is always right before closing the </body> HTML element.

1 Like

And we are having the same issue with rocket loader. Right now rocket loader is disabled because it brokes the site.
It seems all Cloudflare scripts are being attached after closing html tag!

Are you able to provide us with your domain?

I guess that is the problem, I suspect he is not closing some tags.

1 Like

How big? A character count would be helpful to know.

As would running it through a validation check:

1 Like

740174 characters in source html (not through Cloudflare)

Checked and although there are errors, none of them seem to be related. For example:
Error: CSS: font-family: is an incorrect operator.
Error: CSS: font-weight: 0 is not valid, only values greater than or equal to 1.0 are allowed.

but it can’t process all the file because it fails with a timeout (maybe the file size again is the reason). I am looking for an online html validator that allows me to share a link with the results.

1 Like

Sure, but CF forumos does not allow me to add links.
www.swanmarket.nl is the domain, and
/product/ergonomische-zitbal-byalex-65-cm/
is an example of the wrong script tag (check at the bottom of the html, and you will see the

</body>
</html>
<script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652eace1692a40cfa3763df669d7439c1639079717194" integrity=........

Home is ok.

Howeer, on a product page, I can see the WP Super Cache plugin and my best guess is the options from it are either wrongly configured or something “on-the-fly” compresses it via “checked option” and caches the webpage as HTML, therefore serves it compressed as gzip in a bit weird way :thinking:


Have you tried disabling the WP Super Cache plugin?

Nevertheless, you’re also using Cloudflare APO for WordPress.

cf-apo-via: origin,no-cache
cf-cache-status: BYPASS
cf-edge-cache: cache,platform=wordpress

I’d suggest you to keep and use only one caching plugin, don’t mix more than one because there were some know issues.

I’d do as follows:

  1. Disable WP Super Cache
  2. Purge the Cache at APO via WordPress admin dashboard
  3. Purge Everything at Cloudflare dashboard
  4. Clear Web browser cache or use different Web browser to test it out again
2 Likes

Thank you for your time analyzing it @fritex, I will try your suggestions and come back with the results.