HostingGreen web hosting packages
TutorialsBeginners guides to SEO & hosting
Beginners guide to Web Hosting
Fewer DNS and HTTP requests
In the previous section we mentioned that the browser must first look up thename of your page to obtain the before proceeding with loading the page. Ideally this should be the only look up that the browser makes during the visit to your site. Suppose, for example that the visitor goes to www. -hat.com; in an ideal situation there would be a DNS A record (giving the IP address directly) for and all other content on the page is relative to www. such as /frame.css or http://www.wight-hat.com/frame.css. The browser will cache (remember) the data returned from the DNS query for a while and so the first page will look up the DNS and there is no need to look up a DNS again. For links to external it is unavoidable to make further DNS lookups, but again make sure that they are all the same where possible.
Avoid domain aliases – If the page had a css file which was actually http://wight-hat.com/frame.css this would be the same file- but the browser does not know this for sure because www.wight-hat.com is technically a subdomain of wight-hat.com. Therefore it would make another DNS request for wight-hat.com before it could download the CSS file. To avoid making unnecessary DNS lookups all your links on a page should be local (without the http://www.somedomain.com bit) or they should all use the same domain.
CNAME DNS entries – It is worth noting too that DNS records often alias the www. version of the domain name by adding a CNAME: an entry such as www.wight-hat.com. CNAME wight-hat.com. Although this works it is slightly slower than just making an additional DNS A record such as www.wight-hat.com. A 22.214.171.124.
Make fewer HTTP requests – Each file to download on a page requires an HTTP request. This is a request from the browser to the server. For instance, there may be the html page, a couple of CSS files, a couple of script files and four images… this will be nine HTTP requests. Since download speeds are much faster now for most visitors with the advent of broadband, many requests actually take longer to process than the download themselves. So to download a CSS file (which is essentially a small text file) the http request and response can often take more time than it does to transfer the file that’s being requested.
For this reason, it is likely to make a huge difference to the page loading speed if you make less requests in the first place. Combining CSS files into one file and script files into one file reduces the requests to a minimum. It may be a bit more messy in terms of your own organisation but will pay off in terms of speed. In addition, since we are going to force the browsers to cache these files in a later section, you should put all the script for the entire site in one file and all the CSS for the site in another file- don’t worry about this making the file sizes much larger, remember the request is the thing taking the time not the size of the file!
Later we will discuss doing the same thing with images but since it is a bit more involved we have given it a section on its own.
Next section: Making browsers cache your content
Index of all our tutorials: Wight Hat tutorials