All my scripts are loading twice and killing my load time

I am running speed/optimization tests on my wordpress site and when CF is enabled, every single one of my scripts are loading twice and it’s killing my loading time. When I PAUSE CF it loads normal. I have been trying to toggle CF options on/off but can’t narrow down the issue.

I am hosting a wordpress site and this is the coverage on page loading while CF is on, with CF paused each of these scripts will only load once…

/wp-includes/js/zxcvbn.min.js
/wp-includes/js/zxcvbn.min.js
/wp-content/plugins/revslider/public/assets/js/rs6.min.js?ver=6.6.13
/wp-content/plugins/revslider/public/assets/js/rs6.min.js?ver=6.6.13
/wp-content/plugins/revslider/public/assets/js/rbtools.min.js?ver=6.6.13
/wp-content/plugins/revslider/public/assets/js/rbtools.min.js?ver=6.6.13
/wp-content/themes/xstore/js/modules/swiper.min.js?ver=1.0
/wp-content/themes/xstore/js/modules/swiper.min.js?ver=1.0
/wp-includes/js/jquery/jquery.min.js?ver=3.6.4
/wp-includes/js/jquery/jquery.min.js?ver=3.6.4
/wp-content/plugins/elementor/assets/js/frontend-modules.min.js?ver=3.14.1
/wp-content/plugins/elementor/assets/js/frontend-modules.min.js?ver=3.14.1

How do you tell they are loading twice?

examining the code coverage on pagespeed.web.dev with CF enabled/disabled

Did your site load fine on HTTPS before you used Cloudflare?

I can also tell it loads twice because when opening a new page, it begins to load then flashes and quickly reloads again. If your on the page scrolling down it will bring you back to the top like a refresh almost.

Yes, it loads fine with CF paused - only happens with CF enabled

What’s your encryption mode on Cloudflare?

Full (strict)

What’s the domain?

mycolift . com

Running a request at web.dev does seem to suggest that a few files are loaded twice - https://pagespeed.web.dev/analysis/https-mycolift-com/y0bbxi4m6z

However loading the site in the browser does not seem to load these files twice.

Maybe try clearing your Cloudflare and your browser cache.

Also, try disabling Rocket Loader if you have it enabled.

Thanks Sandro, disabling Rocket Loader / clearing cache was the first things I tried… I am seeing the discrepancy between pagespeed and browser as well… not sure what to make of it but I was trusting my eyes with the double load because I could actually see it happen

If there are such content issues, it usually is Rocket Loader. Apart from that Cloudflare tunnels content more or less one-to-one. If you can’t reproduce it locally, it will be difficult to debug, as there is no further insight provided by web.dev.

Just to verify, you do not have any Workers running for your domain or any Cloudflare applications configured, right?

No workers running or CF applications - I was running CF super cache wp plugin but deactivated it to try and narrow down the issue

Maybe web.dev ran on some cached version. I’d clear the Cloudflare cache and try a brand-new run on web.dev. Enable development mode on Cloudflare before that, to avoid caching and correlate the requests in your server log.

If you do not have Rocket Loader enabed, the issue should really not be Cloudflare related at this point.

Sandro - thank you for all your help so far!

I followed your instructions and after some testing I learned via my server error logs that CF is triggering Mod Security (web application firewall) error with my server hosted on Dreamhost. I tested with Mod security both ON and OFF and the result was the same… As long as CF is on the double loading appears.

Here is the error log:

That seems to be a warning though, not an error. While Cloudflare generally does only tunnel requests, the request is still a new one, so it is possible that request would be slightly different from the browser request and that fires a mod_security rule on your end. I’d debug that to find out what exactly fire that rule, however that should still not execute requests twice.

As mentioned, it does not seem reproducible in a browser and that suggests it may be an issue with web.dev. But even if the browser requests a file twice, that would be because your site requests it twice, Cloudflare can’t tell the browser to do that.

1 Like

Hey, you were absolutely right! Can’t believe I didn’t think of this earlier. So, I ran my performance test through GTmetrix and another alternative, and the performance was stellar. There were no issues with scripts double loading. The inability to reproduce the double scripts in the browser, along with the two alternative speed testing sites showing the same, I think is strong enough evidence to come to the conclusion that it is a page speed error. I’ve been relying on page speed insights for so long, and I never thought it would have me chasing my tail like this.

Thanks Sandro for taking the time to help and sharing your knowledge. I’ve learned so much from you in this thread and I agree - you are the MVP!

1 Like

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