Add HTML app + Jquery

I have decided to remove the script tag from the head and moved it to load thru add HTML app, the performance has been improved but my site has some inline jquery script (document ready method) and because of that the functional of the site disappeared and i see in the console error “Uncaught ReferenceError: $ is not defined”. I tried to move the location to the head and body (all options) and still its showing this error. How can i make it work together?

The only way to offload jQuery is to also offload the inline jQuery script. You could move this into a new external file and then load it in the same app, potentially. I’m not sure which app you’re using or how your website is built, but theoretically this would be possible.

I can’t really touch the inline scripts though its weird it not working because i placed the scripts in the same location. how does Cloudflare load it? I googled this error and it says that its because the jquery did not loaded, in fact it does loaded but not in time…

What app are you using? And/or, what’s your website URL?

It may be adding it with the “defer” or “async” attribute on the script tag, and this means it won’t be blocking later scripts, which could be causing the problem.

jQuery is one of those things, especially with a Wordpress site (for example) that it’s usually worth taking the performance hit to load it in the header, as it just causes compatibility issues trying to defer it.

I am using, there is no blocking issue as i see its just that the jquery function can’t find the jquery file in time or at all and therefore it gets the error, although i see the scripts loaded finally

I mean “script blocking”. You need the jQuery script to “block” the inline script, in order for them to be processed in the correct order. The problem at the moment is that you don’t have a blocking issue :slight_smile:

I’ve not used before, so I’m not sure I can help much further, but you’re simplest solution is probably to put jQuery back in the head where it will load first and be available for any inline scripts.