I can't properly add in the CDN for moment.js to my HTML page. I'd rather just add a link in my html than install. Anyone know how to this? I've tried a few CDNs and nothing is working. Is there a reason to put the link in the head vs just before closing body tag with other JS links? I've seen it done both ways.
-
https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js – Vipul Singh Jan 09 '18 at 16:46
-
Well just add the script tag. Moment doesn't depend on other plugins nor the DOM. So you can add it in the head tag, but for convention it's better to add it before body closing tag. – Phiter Jan 09 '18 at 16:46
-
4this: `` – Phiter Jan 09 '18 at 16:47
-
your second question is a duplicate may be related to https://stackoverflow.com/questions/3531314/should-i-write-script-in-the-body-or-the-head-of-the-html – Matteus Barbosa Jan 09 '18 at 16:47
-
I would place where it looks more cohesive. Perhaps you sign the loads with async and defer to deal with the loading order, depending on the scripts relevance – Matteus Barbosa Jan 09 '18 at 16:50
3 Answers
If you want to point to the latest,
You can link directly from their website.
Here is the link,
https://momentjs.com/downloads/moment.js

- 8,353
- 4
- 51
- 54
You can use the following link for the moment.js:
<script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>
The imports done in the head
suppose to load onto DOM
before the content of the body vs at the end near the body
closing tag, when all the code above supposedly have been load onto the DOM
However, we often deal with async code when working with javascript.
So, if you have a local script that depends on an external CDN
library to be available, you can add defer to the end of your local script. the defer
will wait for all content to be available on DOM
to continue loading.
example:
<script src=xxx" defer></script>
I would place where it looks more cohesive. Perhaps you sign the loads with async and defer to deal with the loading order, depending on the scripts relevance. Find more on the primary discussion.

- 2,409
- 20
- 21