So I'd like to get it conditionally included. Right now, the easiest way is to base it on the server name, so I can have my live site served both as the regular server name as well as an alternate, development-oriented name. Same site, two names.
Then, I can add the script to only run on the site named for development. After doing a bit of research, here is the solution I found, adapted:
This works great on Chrome. Unfortunately, in IE, the globals I'm setting (group number is the important one) aren't seen by the script and it complains.
I'm no JS jockey. Can anyone help me with a better technique?
If you have access to server-side language, you could just conditionally include the markup based on header responses.
If not, you could load the initialization part regardless of who loads the site and then just include the protonotes script as you're doing now. You're really not adding any real overhead by doing that.
[Preferred] If the pages are dynamically generated using some server-side technology (e.g. PHP, ASP, JSP), use that to determine whether the script gets included.
[Simplest] Declare the globals first, then import your script:
[More sophisticated] If you want to up your game a little, you could define a method to add a script and define a callback that gets executed when it's loaded. There are no significant advantages, but in my opinion it does look cleaner, avoids
document.write(which I personally find a bit icky), and you get to flex your JS muscles a bit more.
For example, using Nicholas Zakas'
Both jQuery and the Google JS API provide equivalent functions to do this if you're using either of those.