For every mistake that is made in your code, your browser has to interpret what it is that it should be doing. Not a problem you think? Well you might be right, but squeezing every ounce of performance should be your key goal. Just using a handful of my favourite tools will highlight any problems that you have very quickly. These include:
- Firefox / Chrome Plugins: Google Page Speed, HTML Validator, Firebug, Web Developer Toolbar and YSlow
- Smush.it
- Jcompress.com
- W3 HTML Validator (bit of a given really!)
<?php
function show_image($url, $width, $height, $alt) {
return '<img src="'.$url.'" width="'.$width.'" height="'.$height.'" alt="'.$alt.'" />';
}
?>
You could include this in your header or whatever and then call it each time you need an image on your page. This way, you are forced to have each parameter so that your image will be displayed properly. The function could also be expanded to include JavaScript, Class and ID parameters etc. but for a quick and easy solution there isn't much else better. You could then apply this theory to other elements on your page and you will quickly then get the hang of things.
Always, always run a validate check to see if your code really does validate. If you are confident in your code being very good, you could think about making your site XHTML 1.0 strict and while this sounds easy, it sometimes isn't and could mean that you have to redesign part of your site to compensate.
Other areas that will offer performance increase are:
- CSS sprites;
- Too much JavaScript;
- Images that are too large for the job, i.e a 16x16 image shouldn't be 10kb;
- Cache as much of your code that won't be changing, i.e. JavaScript;
- Minify your HTML, CSS and JavaScript;
- Avoid DNS lookups;
- Too many HTTP requests within your page;
No comments:
Post a Comment