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.

I created a clone site so as to test it worry-free. I have disabled wp-cache plugin, purged cache, loaded page from incognito mode with browser cache disabled. Same behaviour.
Then I enabled rocket loader feature on CF, with a page rule, only for the cloned site. And now you can see at the bottom of the page that both cf analytics and rocket loader scripts are added after html tag is closed.
You can check it here.

  • Domain: clone.swanmarket.nl
  • Path: /product/ergonomische-zitbal-byalex-65-cm/

Bottom html:

</body>
</html>
<script src="/cdn-cgi/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js" data-cf-settings="aede285928397748c7bd1790-|49" defer=""></script><script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652e...........

I created a support case. They requested me to leave the cloned site while they escalate the issue. I will leave here any findings.

1 Like

I am afraid I have found an issue. You’ve got the issue of unclosed tag before, kindly double-check your website code, ti should be starting within the element:

<div id="login-form-popup" class="lightbox-content mfp-hide">

If it’s a plugin, try disabling it, clear the cache and re-check. If that’s the case where it starts :thinking:

Or actually, somewhere before as I analyze it …

Two div enclosed but not used somewhere after enclosing below one:

<div class="social-icons follow-icons" >

And some other div.

I wonder how it ended up and why Cloudflare adds it’s script tags of the Rocket Loader and other at the bottom to the wrong place either because of it.

Also, I wonder if the teme is closed with body and html properly or they were added by some minify or Web browser behaviour :thinking:

Can you try to disable WP Super Cache and Auto Minify options at Cloudfalre for clone sub-domain?

Wonder if disabling all plugins changes anything, including Woocommerce just to see if with the installed theme is ok or not :thinking:

I found the plugin that is triggering CF error. The “woo-variation-gallery” plugin, it adds some fancyness on how images are displayed. I re-enabled all plugins, also wp-cache and when I disable “woo-variation-gallery” plugin (only that one), CF adds the scripts correctly.

is still there and it does not seems to bother.

I still don’t understand why browser displays it correctly but CF is not able to parse it and add scripts after closing html tag. It is not a normal behaviour.

With the plugin enabled, try loading the page directly from the origin. Either using curl --connect-to ::IP_ADDRESS, or with Cloudflare paused. Then see if there’s anything after the closing html tag.

Nothing strange, only the wp-super-cache comments. Is the same behaviour whether we have super-cache or not. The issue only shows up with “woo-variation-gallery” plugin. Tried disable super-cache and enabling woo-variation-gallery, and CF fails to add the scripts.
No reply from CF support yet.

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