Matthew Salsamendi
Matthew Salsamendi

Reputation: 294

Does using a sub-domain for static resources improve performance even if network latency is introduced?

We are working to switch our web infrastructure to use a single sub-domain for static resources as per Yahoo's web standards advice. This is theoretically supposed to improve performance because it will allow browsers to make requests asynchronously to grab the static resources that are needed. We are using Cloudflare as a CDN and I'm a little bit worried that the additional latency that will be added with DNS pointing to Cloudflare's any casted IP range (while only 15ms) may defeat any performance benefits that would be gained by switching to a static sub-domain.

Upvotes: 2

Views: 778

Answers (1)

Ofer Zelig
Ofer Zelig

Reputation: 17508

The additional latency is negligent. The browser/client will only parse the new static subdomain once. Overall, it really pays off because of several reasons:

  1. The browser might more efficiently parallel requests to the different domains (although recent developments make this a bit of a thing of the past, and in fact some researches suggest that domain sharding is even worse today)
  2. Your CDN source will serve files with better optimized headers. No headers for cookies (which are not needed), better headers for client and proxy caching.
  3. Most important of all - CDNs spread the static content all over the globe (what's called 'Edges') so your customers will fetch the static content from servers close to them, therefore reduce latency to a minimum.

Regarding your last paragraph, I think there is some confusion... static files are not meant to be fetched from inside your web server. Your code should access local files (this is not always the case as some files can be stored in a NAS or so). Static files in static subdomains / CDNs are fetched from your users' browsers, not from your web server. Your web server creates the pages themselves (probably dynamic ones, such as PHP, ASP.NET files etc.) which render HTML to the client. That HTML references other static resources: JS, CSS, Images etc. - these are resources that should ideally reside in some sort of a CDN.

Upvotes: 1

Related Questions