#35 Slow loading of Javscript def files

Interface (5)

When a user first connects to our site, all the Javascript files are loaded serially. This amounts to about 8 seconds, even when using a fast connection. Round trip time alone between Europe and US is responsible for about half of this time (I checked it carefully using Firebug). What's worse is that during that time, the browser window is frozen (the bottom left corner showing "Loading jsMath..."), and one cannot even scroll down the page.

Is there any way to load jsMath's Javascript files in parallel? I think that this is in principle possible. Alternatively, can one combine them into one file? This would save lots of the round-trip time (currently I have about 10 .def files loaded since I added three extra fonts).

Finally, thanks for this great software!


  • There is no easy way to make jsMath load its files in parallel. You are right that it is possible, but it would take a substantial rewrite of the code, and that is not likely to occur.

    In terms of combining files, it would be possible to put three of them together, but not all of them. I'm not sure why you are seeing 10 .def files for the three fonts (there should be at most 6, depending on whether you are using image fallback mode or not).

    What three fonts are they? Are they in use on all your pages? A better idea than loading lots of font files initially might be to define the macro for the font so that it autoloads the font when used (saving the extra file loads when the fonts are NOT used). That is done via the jsMath.Extension.Font() function, which you can add to your easy/load.js file. For example,


    would defing \bbold so that when it is first used, it loads the bbold10 font (which redefines \bbold to actually access the font). You can add such definitions for any of the fonts you want to use. Put them just before the "do not edit below" comment at the bottom of the easy/load.js file.

    Hope that helps.


    • status: open --> closed-accepted

  • Anonymous

    Many thanks, Davide for this helpful answer!!

    I realized what I did wrong: I added "msam10" and "msbm10" to the "loadFonts" line of "easy/load.js" even though they are loaded automatically and on-demand by the "AMSsymbols" extension (which I also load!). This not only slowed down things, but also broke the definition of "mathbb". Anyway, the situation is much better now. Maybe the documentation can be a bit more clear about this issue of loading fonts...

    I am still loading the "cmss10" font manually through "easy/load.js". I tried adding the line:
    to easy/load.js as you suggested, but unfortunately I get the error message "jsMath.Extension" not define in the Javascript console. I guess the module is not loaded at that time. I wonder if there's a way to load "cmss10" dynamically too (as this would save two more "def" files).

    Many thanks,

    • status: closed-accepted --> closed-fixed
  • Yes, better documentation would help.

    Sorry about the mistake with easy/load.js. I've been doing so much work with MathJax (the successor to jsMath) that I forget about the differences sometimes.

    You need to put the jsMath.Extension call not in the easy/load.js file, but in a SCRIPT tag just after loading easy/load.js:


    I think that will make it work for you.



  • Anonymous

    Dear Davide,

    Unfortunately this new way of loading the font also does not work, presumably due to synchronization issues (I still get "jsMath.Extension" not defined). Putting the command inside "jsMath.synchronize" also didn't help. Applying this command manually later through the console *did* work. That's why I suspect synchronization issues.

    Anyway, I'm already very happy with the current solution, so please don't waste more time on this.

    I am really looking forward to installing MathJax on our journal's (Theory of Computing) system. It seems very exciting! Keep up the good work!

    Best wishes,

  • Argh! I keep forgetting how hard it was to configure some things with jsMath. That was one of the things I improved with MathJax, and it is hard to go back to when it didn't work easily.

    Since you are OK with the current arrangements, I'm not going to work out the details for this, as they are more complicated than they should be.

    Good luck with the journal.