Archive for the ‘Website Optimization’ Category

MySQL Date_Format()

Part of SEO now is improving the time it takes for a webpage to download to the user’s computer – the quicker it loads, the better.

There are many ways to shave off a half second here, or half second there (for example place your common images into a sprite and place them using CSS as opposed to downloading them all one after another), but there is so much more that your can do!

We all know about placing as many (if not all) of our CSS and javascript into one or two files (as opposed to seven or eight), and only loading the javascript files at the bottom of the page instead of in the head tags is another way to speed up the download time.

That’s the easy stuff! What about the back end stuff? You can optimise database queries and squeeze out even more milliseconds!

For example, a MySQL database will store a date in a yyyy-mm-dd format. In order to display it in the standard dd-mm-yyyy format the standard approach is to get the date out of the database and using PHP, explode it then put it back together again the desired format.

There is a better way!

Date_Format() is a MySQL Function that can be used in a MySQL Query to, as the name suggests, format dates, e.g:

SELECT DATE_FORMAT('date','%d / %b / %Y') AS showdate FROM table ORDER BY date DESC

What this line of code is doing is fetching the date from table and formatting it into the dd / Mmm / yyyy format (for example ‘04 / Jun / 2010′), ready for processing in our PHP script. Of course there are many ’specifiers’ that can be used to customise the results as are required by your script, for example %D will show the day of the month with the English suffix (0th, 1st, 2nd, 3rd, etc). As a side-note, ranges for the month and day specifiers begin with zero due to the fact that MySQL allows the storing of incomplete dates such as ‘2014-00-00′.

For a full list of specifiers for the Date_Format function, visiting the MySQL Date and Times Reference Manual.

There’s a whole chapter in the MySQL Reference Manual dedicated to optimising which is definately worth reading, as squeezing every little bit of performance out of the database can help.

Sitemaps – A Road Map To Your Website

Sitemaps are the best way to inform search engines the presence of pages on your website. They are designed so the robot does not have to crawl your website for links itself, instead it can utilise the contents of the sitemap file so it instantly knows about any page of your website contained within the file. The robot will still index your site anyway, but the sitemap ensures it can do this more quickly and effectively.

There are 2 main types of sitemap. HTML sitemap and XML sitemap:

A HTML sitemap is the one that your visitors can use if they want to quickly find a specific page on your website, or if they simply get lost in a complicated site structure. Generally a HTML sitemap will contain simple text links to important pages on the website, such as the homepage, a contact page, terms and conditions, etc. Some automatically generated sitemaps also include useful description information too, so visitors can choose if the page is right for their needs before visiting it.

An XML sitemap is the one that the search engines use. It’s in a search engine friendly format, but not a user friendly format, and any user attempting to view it will be greeted by XML code they likely cannot understand. Search engines however, love XML code because it is specific to their needs and doesn’t contain non-relevant information. There are lots of ways to generate an XML sitemap, simply do a search for “sitemap generator”. Most of these will also generate the HTML sitemap for you, but you may want to make one yourself using your websites template rather than a generic one.

There are also less common sitemap files you can come across occasionally, and this is the RSS sitemap. Normally an RSS feed is used for site updates such as news posts, blogs, or forum posts. In instances where the site does not have any of these, an RSS sitemap can be generated instead and linked in the website header. This allows users to find out about new pages or changed content quickly, just as they would with a regular RSS feed.