Options

Conditional includes?

wellmanwellman Registered Users Posts: 961 Major grins
I had kind of a crazy idea. Walk with me down my thought process...

I've seen some concern expressed over the amount of JavaScript code that has to be loaded in order for some of these fantastic hacks to work. In other words, why should Jane and Joe User have to wait for devbobo's awesome Bulk Thumbnail Zoomer code to be downloaded when only I (the site owner) actualy use the code. Or why should BWG's slideshow code have to load up on pages where there are no slideshows?

So that got me thinking whether there was such a thing as a conditional include in JS. If I could place devbobo's code somewhere and only "include" it when I'm logged in to the account, it would save Joe and Jane a few milliseconds of page load time. It would also save SmugMug's servers a bit. Granted, pictures are far more data intensive than text.

So let's say there is such a thing as conditional includes. JS includes seem to be of the form:

<script src="file.js"></script>

The problem is that most folks don't have a server they can stick a text file on, and even if they did, we're now requiring two servers to be up and running for our pages to work properly. What would be awesome is if there were some way to stick code on an HTML-only Smugmug gallery (say in a div classed "jsCode"), extract that code into a string variable, and then include it based on some test.

I've tried a few things (like trying to document.write an include statement for a js file), but nothing has worked thus far. Can it be done?

Comments

  • Options
    devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited March 8, 2006
    Greg,

    You would have to do something like this....
    oScript = document.createElement("script");
    oScript.src = "file.js";
    document.head.appendChild(oScript);
    

    Hope this helps,

    David
    David Parry
    SmugMug API Developer
    My Photos
Sign In or Register to comment.