View Full Version : CYB Chatbox external javascript
Frosty
08-25-2011, 10:21 AM
Hey everyone,
Is there any way we can put the javascript of the CYB Chatbox in a file? It would surely decrease the page load, and source of the page wouldn't be so messy either.
I tried to do it myself, but it wouldn't load the Chatbox, I assume it's because it loads it like a normal js file, and variables probably can't work.
Any ideas? Thanks...
I'm not a js expert, but I think you should just be able to put the code in a file and put a <script> tag in the html. Did you put <script...> in the same place you took out the code?
Frosty
08-25-2011, 12:40 PM
Yeah, of course. But the problem is that js has variables, and when you put it in a file and go directly to it, variables won't work - obviously!
It works if it isn't external. :/
Oh, you mean that it has template conditionals and PHP variables (javascript also has it's own variables, so I didn't understand what you were getting at).
What you can do is find all the PHP variables it uses, then put them in a template that outputs js code that simply sets a js variable to that value. Then change the js code (that you're trying to move to a file) to use the js variables, and change the template conditionals to js 'if' statements.
Another way would be to set the src of the scirpt tag to a php file that renders the template and returns the js. But that way you wouldn't be able to allow the browser to cache the output which I guess is the point of doing this.
Edit: The headinclude template already has a section that sets js variables, it looks like this:
<script type="text/javascript">
<!--
var SESSIONURL = "$session[sessionurl_js]";
var SECURITYTOKEN = "$bbuserinfo[securitytoken]";
var IMGDIR_MISC = "$stylevar[imgdir_misc]";
var vb_disable_ajax = parseInt("$vboptions[disable_ajax]", 10);
// -->
</script>
You could add yours there, but you'd probably want to have some sort of template conditional around it so you weren't putting it in every page (like maybe <if condition="THIS_SCRIPT == 'misc'">)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.