My Twitter

Decrease loading times via .htaccess

April 15th, 2009

Here is a really nifty trick I’ve been using for a while to decrease the time a page takes to load. Add the following lines of code to your .htaccess file:

FileETag none # Turn off eTags
<IfModule mod_expires.c> # Check that the expires module has been installed
ExpiresActive On
ExpiresDefault "access plus 10 years"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType application/x-unknown-content-type "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
</IfModule>
<IfModule mod_gzip.c>  # check if gZip support has been installed
mod_gzip_on         Yes
mod_gzip_dechunk    Yes
mod_gzip_item_include file          \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler       ^cgi-script$
mod_gzip_item_include mime      ^text\.*
mod_gzip_item_include mime      ^application/x-javascript.*
mod_gzip_item_exclude mime      ^image\.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

This quick and easy method tells the user to cache files which are unlikely to change for 10 years (feel free to change the amount of time) and HTML for 1 second. It also turns off eTags.

Update: I also added a another piece of code I use which turns on Gzip, which reduces the amount of bandwidth required to transfer a file.

Internet Statistics – March 2009

April 15th, 2009

Browser Statistics

march-09_browser-trendIE8 has been released, but unfortunately will not be a high priority until around the 20th April 2009.

Biggest Rise: Safari (3.09%)
Biggest Fall: Other (-2.82%)

OS Statistics

march-09_os-averageWinXP is still very dominant, but is losing ground to Vista and other OS’s.

Biggest Rise: Vista (0.31%)
Biggest Fall: WinXP (-0.39%)

Internet Penetration

march-09_internet-penetration-trend

Latin America/Caribbean and North America had the same increase in Internet Penetration in March 2009. Could the gradual increase in Internet Penetration be a sign that the recession is soon to subside?

Internet Usage

march-09_internet-usage-trend

Internet Usage stayed relatively constant in relation the previous month, even though there was an increase in internet penetration.

7 Essential Free Programs

April 10th, 2009

Here are some free programs I consider essential for all PC’s.

1. CCleaner

CCleaner is a freeware system optimization, privacy and cleaning tool. In a nutshell this deletes all the temporary files and rubbish that build up over time. It also is able to easily clear up the Windows Registry (Which after a few uninstalls or installs is worth a look).

CCleaner’s Homepage

2. Firefox, Opera or Chrome

Forget Internet Explorer, make your computer more unique (and possibly more secure) and take on a different browser. There are loads to close from, but personally I like Mozilla Firefox the most, as its open source nature means that it can be adapted and (if a bug appears) fixed very quickly.

FirefoxOperaChrome

3. Tweak UI (A Microsoft Powertoy)

Ever wanted to fix those little annoyances in Windows? Well Microsoft has a neat little application which lets you modify some of the hidden settings in windows.

Microsoft Powers Toys

Read the rest of this entry »

Conditional Comments

April 8th, 2009

Most coders and designers will tell you Internet Explorer (Especially IE6 below) is a pain to work with, but I tend to disagree. What most people forget is that even though IE is full of bugs and oddities everything can be fixed, with just a few lines of code.

How to use Conditional Comments

Conditional Comments let you execute sections of code in just IE, so you can import custom CSS sheets (to deal with IE’s weird rendering engine) or special JavaScript; here is how to use conditional comments:

<!--[if IE]>
This will only show for Internet Explorer (IE)
<![endif]-->
<!--[if !IE]>
This will only show if the client is not using IE.
<!--[endif]>
<![if IE 6]-->
Only shows on IE6
<!--[endif]>
<![if lte IE 6]-->
Any IE browser less than or equal to version 6.
<!--[endif]>
<![if gte IE 7]-->
Any IE browser higher or equal to IE 7
<!--[endif]>

Just place snippets of the above code anywhere in your code. If you want more information conditional commenting take a look at the Conditional Comment Wikipedia page.

5 Tips for Coding Cleaner PHP

April 6th, 2009

PHP is lovely, though if you ever work with other people having good code is important. Here are some tips to improve your code.

Comment & Document

It’s really important that people understand why you are doing certain things in certain ways. Adding a quick comment above sections of code should be adequate, but documenting classes and functions (Even if it’s in a Wiki) is fantastic.

Give Variables, Functions and Classes Meaningful names

Nothing is worse than trying to figure out what a function called “SIDFE()” does. Give everything a name that if someone else looked at it, they could figure out what it does. The above is a real example I have come across while adjusting a clients website, if the other programmer had called it something like Scan_Incomming_Data_For_Evil() it would have been a lot more straightforward.

White space

whitespaceAs you can see, a little space here and there makes life a lot easier.

No one likes to have to search for the start of a function. Make sure you indent your code and keep it easy to read quickly.

Never Delete – Comment out

This one is a little hard to grasp, but imagine you just fixed a bug (say 100 lines of code to fix it) and something else has broken. It makes sense to be able to go back and see the old code without modification of the new code. Also, doing this helps people see where an old bug was (assuming you comment that the section of code is evil) for future reference.

Use Braces

Braces are those neat } and { things. If you don’t use them on various functions it’s a pain to figure out where a loop starts and finishes. This is especially important when programming on a large scale because no one likes debugging fugly code. Here is an example of good and bad code:

<?php
/* Examples of annoying code */
if ( $coder === 'Silly' ) bang_head(); 

while ( $coder === 'Silly' )
    bang_head();

/* Examples of good code*/
if ( $coder !== 'Silly' ){ Drink_Beer(); }

while ( $coder !== 'Silly' ){
    Drink_Beer();
}
?>

Read the rest of this entry »