XF 2.3 Running Custom Javascript File

Grumpy Squid

Member
Licensed customer
Hello,

Awhile ago someone wrote some custom Jquery code that we keep in a javascript file on our server. At some point it stopped working. I know Xenforo 2.3 doesn't support Jquery so I had two questions:

1. When looking up the issue online someone mentioned the syntax to include external javascript files. The post is from 2012, is the syntax still
Code:
<xen:require js="assets/custom.js" />
Would I be able to stick this in our page_container somewhere and have it run the javascript written in that file?

2. When including an external javascript file like this, does it being jquery matter? Would it still work even if Xenforo doesn't support it?

I'm guessing the reason this doesn't work is because the code in the custom file is Jquery, but I'd like to make sure.
 
Hello,

Awhile ago someone wrote some custom Jquery code that we keep in a javascript file on our server. At some point it stopped working. I know Xenforo 2.3 doesn't support Jquery so I had two questions:

1. When looking up the issue online someone mentioned the syntax to include external javascript files. The post is from 2012, is the syntax still
Code:
<xen:require js="assets/custom.js" />
Would I be able to stick this in our page_container somewhere and have it run the javascript written in that file?

2. When including an external javascript file like this, does it being jquery matter? Would it still work even if Xenforo doesn't support it?

I'm guessing the reason this doesn't work is because the code in the custom file is Jquery, but I'd like to make sure.
Code:
<xf:js src="myaddon/scripts/main.js" />
JS written for versions prior to 2.3.0 is not compatible with 2.3.0. If you’ve upgraded, you’ll need to update the add-on as well.
 
If it is a small jQuery (.js) file. It should be pretty simple for someone to re-write in pure javascript for you. This would be the simplest way to go to make it compatible with XenForo 2.3+ without adding jQuery support back in (which is not recommended).

If its a small file you might even be able to paste the code into a free AI (ChatGPT, Grok, etc) and have it try and re-write it for you. It its small enough and not to complex I'd say its 50/50 whether what it outputs will work for you without needing additional tweaks. Or have one AI rewrite it then copy that to another AI and ask if the first AI rewrote it correctly, your odds will be even better. This would take all of about 10 minutes.

As for syntax, as said above, it has changed, it is now...
Code:
<xf:js src="vendor/addon_id/filename.js" />

If the addon was written that long ago, there is a good chance for other incompatabilities in it also.
 
Back
Top Bottom