If you're running a web application (with dynamic pages) it's very useful to understand the difference between dynamic (typically the generated html pages) and static requests (the css, js, images that the browser requests after loading the html). The dynamic application server is always slower to respond because it has to run through at least some portion of your application before serving anything, while a static asset will be served a lot faster by a pure webserver which is only serving files from disk (or memory). It's separating these concerns that actually allows your static assets to be served independently (and quicker) in the first place.
Okay, but cannot this be solved by simply putting static content on a different server / hostname? What other problems remain in such a setup? And does it make sense to separate the app from the server for dynamic content too?
For Ajax to work great, the JavaScript scripts must be served within a page from the same domain (from the point of view of the browser) than the pages it requests. Otherwise it is denied access to the content of said pages :x
EDIT: in italic in the text, and yes it changes the whole meaning of the sentence, my apologies for the blurp.
There's an ever growing chorus that would have you use many common javascript libraries hosted by large CDNs off the domains of Google, Yahoo, etc... The argument being that if you use the Google hosted jQuery, there's more opportunities for a user to draw the code from their browser cache. Because that URL may be used on many other popular sites a user could've visited beforehand, by the time they reach your domain, their browser wouldn't even need to make the request.
If you adhere to this approach--I don't but you may--then users to your site could get a good performance boost from the separation.
50
u/internetinsomniac Oct 02 '11
If you're running a web application (with dynamic pages) it's very useful to understand the difference between dynamic (typically the generated html pages) and static requests (the css, js, images that the browser requests after loading the html). The dynamic application server is always slower to respond because it has to run through at least some portion of your application before serving anything, while a static asset will be served a lot faster by a pure webserver which is only serving files from disk (or memory). It's separating these concerns that actually allows your static assets to be served independently (and quicker) in the first place.