CDN hosted javascript libraries and downloaded and minified

Look here for some information.

My setup recently changed to work with Grunt and LiveReload. It's great for making small mini css files from scss files, so it's great.

However, what's best in terms of JS? I am currently using CDN for most things like jQuery, Isotope, TagIt, etc.

I have some custom JS files that contain my own code for my site, so it's okay for me to combine and minify them. I understand that many queries have performance implications, hence minification and concatenation.

But is it better to download all libraries and compile them into one JS file for inclusion in my site? Or keep external related CDNs?

+3


source to share


1 answer


There are really two questions here:

  • Safety
  • Performance

Safety



From a security standpoint, JavaScript hosting puts you in charge, whereas relying on JavaScript from an external domain essentially trusts that domain for the security of your domain (which, depending on your level of trust with this third party, may or may not be acceptable) ... If you are using advanced security options such as Content-Security-Policy

, you may need to do additional work to allow these external scripts (for example, to whitelist CDN's domains script-src

).

Performance

In terms of performance, using the CDN-enabled version, especially if it's popular, can give you better caching; however, hosting it yourself and combining it with other scripts can result in fewer requests. In terms of what's actually happening faster, you will need to do some of your own measurements (I recommend doing an a / b test with real user traffic, which will give you an idea if real users really have CDN capable versions resource is cached or not).

+4


source







All Articles