I am using jQuery, angular, bootstrap, along with some custom js files. Currently, I have everything bundled into one script. Since, jQuery, angular, and bootstrap are available via CDN, is it better to just grab them from the CDN or should I keep those bundled with my scripts?
-
Better by what metric?– NeilJul 29, 2015 at 13:48
-
@Neil - In general, but I would say speed and size?– xaisoftJul 29, 2015 at 13:52
-
1Combining the files reduces the number of requests, which can speed download. Pulling the files from a CDN that is widely used improves the chance that the files will already be present in the user's cache from visiting other sites. If they haven't, though, they'll get slowed down from additional DNS and HTTP requests. `– Alan ShutkoJul 29, 2015 at 14:00
-
Most people tend to prefer bundling, as you don't depend on another server being up to work and you only have to download a single script once.– NeilJul 29, 2015 at 14:30
-
I ran across this answer and felt it explains bundling well stackoverflow.com/a/28233712/32240– RayOct 7, 2016 at 4:29
1 Answer
My advice would be to bundle all of your own scripts together, and load common third party scripts from a CDN. It gives you the best of both worlds - your scripts download quickly, and third party scripts are likely loaded directly from the end user's cache.
-
3Just a suggestion. Have a copy of these scripts in your repository otherwise you are totally dependent of CDN content management. Same goes for any js lib you might been using. Js ecosystem is quite fragil and volatile.– LaivNov 16, 2016 at 21:14