5 Replies Latest reply on May 23, 2010 1:06 PM by Dirk Becker

    javascript caching

    PeterPow Level 1

      Hello guys,

       

      in our IDS implementation we are using lots of javascript functions. This functions are defined within 2 files, one of them contains about 2000 rows. The problem is, that the include of this file with the

       

      #include...

       

      statement takes about 80 ms. This is a long time, especially when you know, that this file only defines methods, nothing is executed at the time of inclusion. Now my question is whether there is a possibility to tell the server to persistently keep this functions in memory with no need to include the file on every request (we are using soap for communication). Maybe there are some tricks to make the IDS JavaScript parser more performant?

      Thanks in advance!

          Peter

        • 1. Re: javascript caching
          Harbs. Level 6

          If you use a persistent engine, you can load all your functions once per session, and it will be available in memory to all scripts running in the same engine.

           

          Harbs

          • 2. Re: javascript caching
            PeterPow Level 1

            what do I have to do to run a "persistent engine"?

            • 3. Re: javascript caching
              Dirk Becker Level 4

              See JavaScript Tools Guide CS4.pdf, page 228

               

              #targetengine enginename

               

              Defines the target JavaScript engine for this JSX file, within the designated target application. Supported by Adobe Illustrator CS4 and Adobe InDesign CS4; other applications ignore the directive.

              For Adobe Illustrator CS4 and Adobe InDesign CS4, if the named engine does not exist, and if the script originates within the application (rather than being executed in the ExtendScript Toolkit or received in an interapplication message), the application creates a new JavaScript engine with this name, which persists for the lifetime of the application session.

              If the script originates outside the application, and the named engine does not exist, the directive is ignored.

               

              Dirk

              • 4. Re: javascript caching
                PeterPow Level 1

                thank you guys, now the javascript files are included only once instead of being included on every request to the server, this makes the whole application more responsive.

                • 5. Re: javascript caching
                  Dirk Becker Level 4

                  I just reminded myself this is the server forum.

                   

                  Some additions:

                  To create a new session e.g. for InDesign desktop / ESTK to try things out, use a startup script.

                  You should also thoroughly test your scripts against leaks - some constructions are not caught by the garbage collector.

                  As preparation install your script and do a test run.

                  Then invoke the garbage collection yourself. Do it twice, it really makes a difference.

                   

                  my_testscript();

                  $.gc(); $.gc();

                  $.writeln($.summary());

                   

                  Repeat the exercise a couple of times, and see whether there are changes in the summary.

                  Dependent on the amount, you better track them down or plan to restart the server every now and then.

                   

                  Dirk