Avoiding constant font reloads

  • rm50

    rm50 - 2009-04-18

    Probably a stupid question, but...is there a way to avoid having the browser reload fonts each time a slightly different page is rendered? What I'd like is for the browser to cache the fonts in such a way that jsMath could use them.

    • Davide P. Cervone

      I'm not sure I quite understand the question.  JsMath has basically three ways to handle fonts.  The best approach is that you can download some TTF fonts and install them in your system so that they are always available to jsMath.  This only requires one download, but it is not done automatically -- you have to do that by hand once and then forget about it.  The second approach is that jsMath could use the unicode fonts that you already have installed on your computer.  This doesn't require any font downloading, though it has no guarantee that they have the math characters in them, and some characters may come from one font while others come from another, and they might not work well together.  The third way jsMath deals with fonts is that if you don't have the jsMath TTF fonts installed, it will use small images of the characters in the TFF font and download them from the server and use them instead of an actual font.  In this case, there is no actual font used, but just a lot of small images.  These are obtained one at a time, but should be cached by your browser as any other image would be; that is, if you use the same math character on another page (from the same site), it should not be loaded again, but used from the cache, but if there are new characters, they will have to be loaded (or if you go to a different site, so that the images are coming from a different server, they will have to be reloaded as well). 

      So it seems to me that jsMath already does what you ask:  either you already have the fonts installed on your computer and jsMath simply uses them (the best solution), or it loads the images from the server and caches them.  The only think that I can think of that would cause jsMath to reload images that had already been used is if the pages you are loading explicitly request that they not be cached (some content management systems may tell the browser not to cache its content, since it may be changing dynamically; that would also apply to the images used on that page).


    • rm50

      rm50 - 2009-04-19

      Perhaps we aren't using terms in the same way. If you don't mind, try going to www.planetmath.org and looking at almost any entry (in the right column). At the bottom of the displayed page, there's a dropdown that allows you to select the view style. If it's not set to jsMath, set it to jsMath and watch what happens. Then click refresh and watch it happen again.

      What I see is that when I load a page, I get lots of messages (from jsMath, I assume, but perhaps not) of the form "Loadings fonts/...", after which the page renders. If I reload the page, those messages happen again.

      What I'm trying to figure out is whether 1) this is just the way it works, or 2) there's something that can be done on the server [or client] side to fix this behavior.


      • Davide P. Cervone

        Yes, you are right, we were talking about different things.  The "fonts" that you see are not actual fonts, but JavaScript files that DESCRIBE fonts so that jsMath knows what is in them.  These files actually ARE cached by the browser, but jsMath has to run them each time a new page is presented since the RESULT of running the javascript is not cached (only the javascript SOURCE).  The message about loading the file just means jsMath is asking for the file -- it doesn't know if it is being obtained from the browser cache or not, and since it could be coming over the network (a potentially time-consuming process), it puts up the message letting you know why it is being delayed.

        Since PlanetMath.org asks for a lot of extra fonts to be predefined, there are lots of such messages as the page loads.  It is actually the display of those names that is slowing things down, not the loading of the files themselves.  If you are a maintainer of PlanetMath.org, you could add the lines

        jsMath.Font = {
          Load: function (name) {jsMath.Setup.Script(this.URL(name),0)}

        to your jsMath/easy/load.js file just before the "Do not change below this" comment at the bottom of the file.  This would make jsMath load font files silently, and should improve your page-load performance.  Let me know if that doesn't work.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks