Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Moment.js CDN Link in HTML

Tags:

momentjs

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.

like image 734
Cecily Grossmann Avatar asked Jan 09 '18 16:01

Cecily Grossmann


2 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
like image 111
Anjana Silva Avatar answered Sep 19 '22 06:09

Anjana Silva


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>

like image 33
Andy Avatar answered Sep 21 '22 06:09

Andy