Juergen Posted December 6, 2017 Share Posted December 6, 2017 Hello @ all, I have included all my external JS files via npm which makes updating of every script very easy. A lot of these JS-libraries are also available on a CDN. My thought was to load the scripts from a CDN if they are present, otherwise load it from my local folder. There are some scripts such as steal.js (https://stealjs.com/docs/StealJS.loading-from-cdn.html) which can be used, but I want to know how others deal with this issue. The best would if the version of the local npm-folder (fe. jquery 2.1.0) would be checked and then the same version would be loaded from the CDN if present, so the local and the CDN version are always the same. Most of the solutions need a hardcoded CDN version that should be fetched. I dont know if this scenario is possible, but maybe someone come up with a good solution. Best regards Link to comment Share on other sites More sharing options...
pwired Posted December 6, 2017 Share Posted December 6, 2017 Do you mean during the time of developing a website ? I always have my js on the same server as the website. I guess loading from a url makes it a bit slower and gives more overhead. Link to comment Share on other sites More sharing options...
dragan Posted December 6, 2017 Share Posted December 6, 2017 Same here. Also, I like to minify + concat everything and deliver just one css and one js file. (AIOM is handy for that, or you can use any Grunt/Gulp task for that) But when I'm in the early stages of setting up a site / app, or just want to play around with different libraries, I usually load everything from CDNs. Also, when it comes to upgrading frontend assets, I don't monitor every new release and run for the latest version. Priority number one is stability. Only when there's a good reason (security bugfixes or major new features that I know I will use), I upgrade JS stuff. 2 Link to comment Share on other sites More sharing options...
DaveP Posted December 6, 2017 Share Posted December 6, 2017 19 minutes ago, pwired said: I guess loading from a url makes it a bit slower and gives more overhead. The browser is already loading stuff from a URL, yours. CDNs do have advantages, that's why they exist. Link to comment Share on other sites More sharing options...
pwired Posted December 6, 2017 Share Posted December 6, 2017 Quote The browser is already loading stuff from a URL, yours. The js wouldn't be loaded from that url, but from another url, so more dns resolvement and traffic from another server. Same like dragan I go for stability and not for every latest and newest. 1 Link to comment Share on other sites More sharing options...
flydev Posted December 6, 2017 Share Posted December 6, 2017 There are as always Pros and Cons about using a CDN. One of the thing I like with CDN is the multiple-request capability. But on other hand, in a security point-of-view, using a CDN if you are paranoïd will make you crazy knowing that someone could modify the delivered JS code to collect data from your users... 2 Link to comment Share on other sites More sharing options...
adrian Posted December 6, 2017 Share Posted December 6, 2017 I am no expert, but I though the two key advantages to CDNs were: 1) Browser caching - if someone already has http:://wwwcdn.com/jquery.min.js cached in their browser they won't need to load it again - this is probably the biggest reason isn't it? 2) CDN servers might be faster than your cheap shared hosting? 1 Link to comment Share on other sites More sharing options...
PWaddict Posted December 6, 2017 Share Posted December 6, 2017 1 hour ago, adrian said: I am no expert, but I though the two key advantages to CDNs were: 1) Browser caching - if someone already has http:://wwwcdn.com/jquery.min.js cached in their browser they won't need to load it again - this is probably the biggest reason isn't it? 2) CDN servers might be faster than your cheap shared hosting? That's 100% correct! Link to comment Share on other sites More sharing options...
Juergen Posted December 7, 2017 Author Share Posted December 7, 2017 12 hours ago, pwired said: Do you mean during the time of developing a website ? I mean on production sites. I always use local stuff on development. In the past I have loaded files from different CDNs (Google, Jsdelivr,...). So I could use parallel downloads instead of serial, which should make the site faster. My strategy was always to load a JS from CDN if possible. If not than fallback to the local version on the server. This needs to look manually if a specific or newer version is available on the CDN. So I am interested in how others deals with this issue and I have read a lot of interesting thoughts here. Link to comment Share on other sites More sharing options...
Recommended Posts