2

How do I specify the following requirement in my html?

When the computer has access to Internet, the source of MathJax.js is https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js;

When it is offline, and the system is Linux, the source is /MathJax/MathJax.js; if the system is Windows, it is /C:/MathJax/MathJax.js. (It would be even better if I can use environment variable in the local path.)

updogliu
  • 6,066
  • 7
  • 37
  • 50
  • I benefit from both Mark's and Nacho's answer. Thanks a lot. However the bounty cannot be divided, I think. – updogliu Jun 19 '12 at 12:41

2 Answers2

3

You can put MathJax in a location relative to your static HTML file:

<script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js"></script>
<script>
if( !window.MathJax ) {
    document.write(
        '<script type="text\/javascript" src="../lib/MathJax.js"><\/script>'
    );
}
</script>

This way your implementation is independent of the OS.

Another option would be to set up the location according to your browser URL:

<script>
var url= location.protocol == 'http:'? 
         "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js" :
         "../lib/MathJax.js";
document.write(
    '<script type="text\/javascript" src="' + url + '"><\/script>'
);
</script>
Nacho Coloma
  • 7,070
  • 2
  • 40
  • 43
2

These other pages might provide you with some new approaches to a solution.

The first one demos how you might chain a list of url's together, and continue trying to load the next script if the previous one fails.

Failover loading of .js from sequence of servers?

You would need to add your logic around Windows vs Linux into that.

Here are some ideas around detecting if the web page is running offline: Detect that the Internet connection is offline?

If you could provide some more information about your application, I can probably come up with some better suggestions. Is this an application users install on their local computer? How do these JS files get onto people's C:\? What is installed when the app installs? How does it run? Is a local server installed as well? Or are the html pages just run from the file system in the web browser?

Community
  • 1
  • 1
Mark At Ramp51
  • 5,343
  • 1
  • 25
  • 30