How to determine if Moment js is loaded from a CDN

I want to backup if js moment is not loaded from CDN. I could not find a useful resource on the Internet, nor on momentjs.com , to find out if Moment js is present.

Here is my code:

<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script> <script> // If moment.js is not loaded, use the fallback if () { document.write('<script src="assets/plugins/moment/moment.min.js"><\/script>'); } </script> 
+7
javascript cdn momentjs fallback
source share
1 answer

The moment joins the window when it loads, so you can do:

 <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script> <script> if (!window.moment) { document.write('<script src="assets/plugins/moment/moment.min.js"><\/script>'); } </script> 
+8
source share

All Articles