3 Replies Latest reply on Jun 23, 2009 4:33 AM by Dirk Becker 

    load javascript function into global scope


      Hello forum,


      i send a lot of different scripts to IDS, but they often need to use the same functions i wrote. Is there a way to define such functions once, and to use them within subsequent scripts, without sending the function within that new script. As my scripts grow, it would be great if i don't had  to put all needed functions in that scripts and send the whole stuff with every request. The only way i see is to use evalFile, but is that a faster and better alternative?





        • 1. Re: load javascript function into global scope
          IanDBrown Level 2

          One javascript can call functions in another file if you use #include "anotherScript.jsx".  I don't know where indesign searches for the included file - it will probably look in the standard locations so it could be that if you put your utilitly script into the standard script location on the server and refer to it that will work.



          1 person found this helpful
          • 2. Re: load javascript function into global scope
            Frobenius5x Level 1

            Thanks a lot, that's really good to know (It would have been even better to see that in some documentation anywhere :-( ).

            The remaining question is, does InDesign cache the included files? If not, i replace one bigger Webservice-Script with one small Webservice-Script plus reading a file from local disc. And i think, the second version is not faster as long as the Webservice-call comes from the same machine. So i only get better structure (well at least, something ;-)).

            • 3. Re: load javascript function into global scope
              Dirk Becker  Level 4

              Launch ESTK

              Help > JavaScript Tools Guide CS4

              Search for "include", "includepath", "startup" ...


              Note that the explanation of application specific startup scripts is a bit lame (almost missing, page 12) in that guide. I can't try at the moment because I'm rebuilding my Server installation right now, but I'd assume you can just follow the pattern from InDesign desktop - e.g. create a folder within the Scripts folder, and nested in that folder another one called "startup scripts" to hold your automatically executed scripts.