Reputation: 167
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.
Upvotes: 3
Views: 3905
Reputation: 9460
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
.
Upvotes: 2
Reputation: 37
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.
Upvotes: 2