Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i use CDN link or download the respective JS?

Tags:

javascript

cdn

I have the option to either use a CDN for Jquery or to download the respective files in my project and then use them.

What should be done considering that the end user of my enterprise product might block all CDN links via firewall.

like image 431
Hitesh Avatar asked Nov 21 '25 04:11

Hitesh


2 Answers

CDN is faster and is preferable in production. Nevertheless what to do when CDN is unavailable / down?
There is a standard trick how to fallback when CDN is unavailable.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script><%-- get from CDN (default) --%>
<script type="text/javascript">//get from local if not available
window.jQuery || document.write('<script type="text/javascript" src="/js/lib/jquery.js">\x3C/script>');
</script>

Note: This solution doesn't work when you load the script from CDN async.

like image 126
Alex Kudryashev Avatar answered Nov 22 '25 16:11

Alex Kudryashev


Using CDN is preferred as it improves the site performance.

Yes, users accessing a site from behind strict firewall rules can face issues to access CDN urls. In that case you can download jQuery. I would advise using bower to install it so you can upgrade / maintain jQuery easily.

like image 33
Harvinder Deogan Avatar answered Nov 22 '25 16:11

Harvinder Deogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!