3

I'm using the excellent requirejs optimizer to compress the code of a web application.

The application uses a lot of third-party libs. I have several options :

  • Let the user download all the third party libs separately from my server
  • Let the user download all the third party libs from a CDN, if available
  • User requirejs to produce a 'compressed' version of all those libs, in a single file

Now, I know that caching and / or a CDN would help with how long it takes to fetch each individual library, however if I have 15 libs, I'm still going to end up with 15 http requests ; which is all the more annoying if the actual code for my application ends up being served in one or two relatively small files.

So what are the pros and cons of each methods ? Also, I suppose I would be actually 'redistributing' (in the sense of common FOOS licenses) the libraries if I were to bundle them inside my app (rather than pointing to a CDN ?)

Any experience / ideas welcome.

Thanks.

phtrivier
  • 13,047
  • 6
  • 48
  • 79
  • Well, if you're using a CDN, then _hopefully_ the user already has some of those same libraries cached, so instead of 15 request, the hope is that it'd be less. – voithos Aug 24 '12 at 15:46
  • It would depends on how the CDN configure caching (if 'must-revalidate' is set, then that's a extra request, albeit a very quick one, right ?) Besides, this does not help the poor user with an empty cache (which I can't help but being scared about...) – phtrivier Aug 24 '12 at 15:54

1 Answers1

0

You could take a look to Why should I use Google's CDN for jQuery? question, why CDN is better solution.

It increases the parallelism available. (Most browsers will only download 3 or 4 files at a time from any given site.)

It increases the chance that there will be a cache-hit. (As more sites follow this practice, more users already have the file ready.)

It ensures that the payload will be as small as possible. (Google can pre-compress the file in a wide array of formats (like GZIP or DEFLATE). This makes the time-to-download very small, because it is super compressed and it isn't compressed on the fly.)

It reduces the amount of bandwidth used by your server. (Google is basically offering free bandwidth.)

It ensures that the user will get a geographically close response. (Google has servers all over the world, further decreasing the latency.)

(Optional) They will automatically keep your scripts up to date. (If you like to "fly by the seat of your pants," you can always use the latest version of any script that they offer. These could fix security holes, but generally just break your stuff.)

Community
  • 1
  • 1
Alexey Ogarkov
  • 2,916
  • 23
  • 28