Reputation: 85
scripts from other providers I would normally include in my application in the following way:
<script src="https://apis.google.com/js/api.js"></script>
However I was wondering whether there is any drawback to just open the url: https://apis.google.com/js/api.js and copy/paste the script inside my application
The advantage for this would be for example when using React - to just copy/paste the script inside the particular component that is using it.
However I'm not sure whether there are any drawbacks - for example whether these scripts might be updated sometimes by third parties (say Google) and it will stop working as I'll have old version copied locally.
Any idea whether there would be any problems with just copy/paste external third parties scripts locally into my code (say React component)?
Upvotes: 0
Views: 2420
Reputation: 4596
The point of a CDN is to avoid downloading common scripts more than once: if you visit website A, and it gets https://apis.google.com/js/api.js
, then you visit website B which also gets https://apis.google.com/js/api.js
, your browser will only download it the first time, and website B will load faster.
Copying the script into your own file will work but you'll lose this advantage.
Upvotes: 3
Reputation: 3721
Yes, actually you can put it in a JS file and then in the Index.html you can do a reference to that file.
<script type='text/javascript' src="../../path/to/the/file/api.js"></script>
Upvotes: 0