by _sfvd on 4/19/18, 7:57 PM with 55 comments
by Someone1234 on 4/19/18, 8:37 PM
They've added a cryptographic hash/integrity and the async/defer attributes to the script tag, but something as essential as a fallback if a script or stylesheet fails to load (which the browser is best placed to know), has no built in functionality.
Instead you're left doing JavaScript tricks which for missing CSS gets a little ugly[0]. But CDN with local fallback (or visa versa) has been common now for decades but yet no official support at all. Honestly if the integrity attribute is specified the browser should just be able to fall back to a cached copy it has (e.g. jquery.1.2.3.min.js has a crypto hash of ABC123, and I have that file already).
[0] https://stackoverflow.com/questions/7383163/how-to-fallback-...
by jakobdabo on 4/19/18, 8:41 PM
I understand that the CDN version of the library may have already been cached by the browser while visiting other websites, but does it really save that much time/traffic compared to self-hosting?
by keane on 4/19/18, 8:49 PM
Original, jQuery CDN:
https://code.jquery.com/jquery-X.Y.Z.min.js
Google:
https://ajax.googleapis.com/ajax/libs/jquery/X.Y.Z/jquery.min.js
Microsoft:
https://ajax.microsoft.com/ajax/jquery/jquery-X.Y.Z.min.js
Microsoft ASP.NET:
https://ajax.aspnetcdn.com/ajax/jquery/jquery-X.Y.Z.min.js
jsDelivr:
https://cdn.jsdelivr.net/npm/jquery@X.Y.Z/dist/jquery.min.js
cdnjs:
https://cdnjs.cloudflare.com/ajax/libs/jquery/X.Y.Z/jquery.min.js
Yandex.ru:
https://yastatic.net/jquery/X.Y.Z/jquery.min.js
by nwah1 on 4/19/18, 8:34 PM
by guessmyname on 4/19/18, 8:52 PM
Nowadays, with all the Node.js stuff that goes around modern front-end, I don't see the point of embedding a JavaScript library from a CDN, unless that library is dependent on a remote service, e.g. Google Analytics, Google Maps, etc… That being said, if you are still maintaining a legacy website that depends on jQuery, you should consider to embed the library like this instead:
<script>window.jQuery || document.write('<script src="/js/jquery.min.js"><\/script>')</script>
by 908087 on 4/19/18, 9:18 PM
by Murrawhip on 4/19/18, 8:28 PM
by jimaek on 4/19/18, 8:39 PM
by leepowers on 4/19/18, 8:39 PM
by kreitje on 4/19/18, 8:39 PM
by justindocanto on 4/19/18, 8:02 PM
by dusan76 on 4/19/18, 9:09 PM
by rharb on 4/19/18, 8:10 PM
by 8bitben on 4/19/18, 8:05 PM
by campuscodi on 4/19/18, 9:43 PM
by petraeus on 4/20/18, 7:02 PM