I want to start using minifying tools such as Minify, Uglify or Closure to speed up the loading of my pages.
My project relies on several bulky libraries (jQuery, Bootstrap, ...).
I'm considering two options:
Option 1: use an official CDN
- Minify only my project files into one
.css
and one.js
file - Serve the (minified) major libraries from a renowned CDN
This would look like this:
<script src="(my cdn)/myproject.min.js"></script>
<script src="(official cdn)/jquery.min.js"></script>
<script src="(official cdn)/jquery-ui.min.js"></script>
<script src="(official cdn)/bootstrap.min.js"></script>
<link rel="stylesheet" href="(official cdn)/bootstrap.min.css"></link>
<link rel="stylesheet" href="(my cdn)/myproject.min.css"></link>
Pros:
- Visitors might already have a cached version of some of the libraries, served by the same official CDN from another website, thus avoiding redundant transfers.
Cons:
- If they don't, this approach will require several HTTP calls (even if they do actually, they will still make a request and get a
304 Not Modified
), and this will increase the page load time.
Option 2: pack everything together
- Minify my project files + the source files of every library, into one single huge file.
This would look like this:
<script src="(my cdn)/myproject-and-libraries.min.js"></script>
<link rel="stylesheet" href="(my cdn)/myproject-and-libraries.min.css"></link>
Pros:
- Number of HTTP calls limited to the strict minimum.
Cons:
- Even if the user has already loaded the jQuery & Bootstrap code from another website, he will have to reload the whole stuff from mine.
Final note
In either case, I will serve the static files (only the ones compiled by myself) from my own CDN at AWS CloudFront, so the question is not about using a CDN or not, or which one is better.
The real question is: pack the third-party libraries with my own, or not?