Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

psmail's avatar

Load multiple JavaScript libraries from a popular CDN or merge into a single file?

Hi

I know this has been covered by JW before, but I am keen to get some clarification about the benefits -

  1. If you only had is it better to load multiple JavaScript libraries from a popular CDN or merge into a single file served yourself?

  2. If you could mix and match, would you minify / combine your own files and grab the popular libraries you used from a CDN or would you download and minify the whole lot?

Many thanks

0 likes
7 replies
SP1966's avatar
  1. I think if the library is popular I would be linking to a good CDN. The likelihood that your user already has it in their cache from another site is going to be pretty high.

  2. If the library was less popular and not to big then I would be inclined to add it to my minified source. If it were less popular and huge I would be torn between using a CDN or just linking the to the file vs. adding to my minified source. Honestly, I've probably got this one completely backwards! :)

davorminchorov's avatar

I think it's better to get all libraries and custom files minified+gzipped into 1 file for performance. If you have multiple scripts from CDNs, your browser will have to load them separately sending extra requests for each file. (if I am wrong, feel free to correct me) It's a good idea to use RequireJS or Browserify to load all the modules async.

accent-interactive's avatar

I minify custom js and then concatenaye all js files, including js libraries into one file. True, it has to load once, but it saves the visitor a lot of http requests per pageview.

1 like
accent-interactive's avatar

I minify custom js and then concatenaye all js files, including js libraries into one file. True, it has to load once, but it saves the visitor a lot of http requests per pageview.

SP1966's avatar

@joostnanveen If you're using something like AngularJS where they have an extremely large user base then the odds are good you're user will already have the CDN version of the library in cache saving both an HTTP request and the extra bulk in your own minified JavaScript. What to do depends highly on how popular the library is IMO.

psmail's avatar

Thanks ... your feedback has helped me to reach the conclusion that I'll use common library CDNs and perhaps move some less common ones to my site and minify and concatenate from there.

Thanks for your collective help.

davorminchorov's avatar

I was looking at the network tab of the app I am working on, and it says that there are 24 requests.(and I don't have all the libraries I need) When I minify it and concatenate everything into 1 file, it will lower the number of requests, which will be a performance boost instead of downloading all libraries from a CDN.

Please or to participate in this conversation.