Local files vs. CDN

The CDN should be used for all static files (.css/.js/images).

Sometimes however javascript or css files can have dynamic aspect to them such as that it would include a unique user string or something of that sort. In this situation the CDN server would have to contact the origin server on every request which would defeat the purpose.

If your CSS and Javascript is static for all users then using a CDN is the right way to go. This would not cause any extra HTTP requests because it would only load the css and js files from the CDN instead of your own webserver (unless you are using inline code). So instead of a users browser loading these requests from your server they would be loaded via the CDN, there is no additional requests you are just changing where to send these requests (again as long as you are currently not using inline code).

Other benefits from using a CDN would be that the CDN server would most likely be located closer to your end users then your origin which will benefit loading times. The CDN servers are also likely setup to serve static content much faster then your origin server by specifically catering the web server for static content.


Using a CDN vs traditional web hosting for delivering your static files such as CSS, JS, and images is commonly preferred. This is because once your files are cached on the CDN's edge servers, your site visitors will be delivered static content from the closest point of presence (PoP) instead of the origin server.

In the majority of cases, this shortens the distance between the client and the server and thus helps improve loading times without adding any additional HTTP requests. This also helps in other areas such as increasing redundancy, taking a load off the origin, etc.


Use a CDN if you need a CDN. If your user is global and spread over a large area, or you have a lot of such content that you don't want to store on your own server, that is when a CDN is useful. Globally, it can speed up access to your content if the server is closer to the user. If you have many GB or Terabytes of static data and a heavy load for access to that content, a CDN can help with that.

However, small, local sites or lightly loaded sites rarely need such things and a CDN can only add one more complication to your set up, operation and workflow, such as caching problems.

Too often I see people use a CDN cause they read they should be using one and no other reason.