Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are CDN Best Practices? [closed]

Tags:

jquery

cdn

I have recently started using the Rackspace Cloudfiles CDN (Limelight), about which I have some questions:

  1. I am using jQuery, jQuery UI and jQuery tools in addition to custom JS code. Also, my site is written in ASP.Net, which means there is some ASP.Net generated JS code.

Right now what I have done is that I have combined all of the js (including the jquery code), except the ASP.Net generated JS into one file. I am hosting this on the Rackspace CDN.

I am wondering if it would make more sense to just get the jQuery, jQuery UI files from the Google hosted CDN (which I suspect would work very well in serving these files, since they will be in many users' cache already)?

This would mean one extra HTTP request, so I'm not sure if it'll help.

  1. Right now I have multiple containers for my assets. For example, in Rackspace I have 3 containers: JS, CSS and Images. The URL subdomain for all 3 is different. Will that lead to a performance penalty? Should I just use one container (and thus one domain for the CDN)?

  2. Is there a way of having the MS ASP.Net generated JS loaded from MS CDN? Would this have a performance hit as per the above question?

like image 337
Donnie Thomas Avatar asked Apr 24 '10 12:04

Donnie Thomas


2 Answers

The #1 way to speed up your website is to minimize HTTP requests (Best Practices from Yahoo). So if you already are serving up your combined CSS files from a CDN, you're doing it. Serving some from google and some from your CDN adds requests.

You can't combine CSS and JS into one file unfortunately, so you're going to be stuck with one request each for CSS and JS. You might want to verify that these are served up GZIPPED.

As far as your images are concerned, the best way to speed those up is to use image sprites whenever possible.

It probably does make sense to serve the files from separate domains as this increases the number of parallel downloads. (Another article from yahoo on this). If your js & css are just two files you can probably put this on one domain and your images on another.

like image 107
Keltex Avatar answered Oct 28 '22 15:10

Keltex


Is is definitely better to have your assets on a different domain.

browsers load web assets one by one or sequentially from a single host. They will not start requesting and downloading the next asset until they are finished with the previous one from the same domain. Therefore, doubling the hosts or domains can accelerate the downloading speed by about 100% because browsers can simultaneously download stuff from 2 different domains.

if cookie or session is enabled on your website, the browser would send the session cookie every time it makes a request to the domain, which sort of is useless because it’s static content – the server doesn’t need the cookie at all to serve static content such as images. It’s not only a waste of bandwidth but also a waste of communication time. To avoid this, serve all static content from a domain that is not cookie enabled.

on the contrary having JS served on sites who update the maintain that JS code could become tricky as you lose the chance to first test your current JS against the new frameworks.

like image 32
Ali Habibzadeh Avatar answered Oct 28 '22 14:10

Ali Habibzadeh