Skip to content

Instantly share code, notes, and snippets.

@pkra
Last active April 12, 2017 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkra/b02253d18a7c611fe0ffb4fbd5d6273b to your computer and use it in GitHub Desktop.
Save pkra/b02253d18a7c611fe0ffb4fbd5d6273b to your computer and use it in GitHub Desktop.
cdnjs redirect example
(function () {
var newMathJax = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js';
var oldMathJax = 'https://path.to/MathJax.j';
var n = oldMathJax.length;
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
var src = script.getAttribute('src') || '';
if (src.substr(0, n) === oldMathJax) {
var newScript = document.createElement('script');
newScript.src = newMathJax + src.substr(n);
script.parentNode.replaceChild(newScript, script);
console.warn('WARNING: cdn.mathjax.org has been retired. Check https://www.mathjax.org/cdn-shutting-down/ for migration tips.')
break;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment