Archive for the ‘twitter’ Category

Saving Link Juice With Nofollow For The “Twitter for Wordpress” Plugin

Wednesday, May 20th, 2009

I have just recently enabled the Firefox Addon SearchStatus while on my blog’s homepage. I was amazed that the Twitter For Wordpress plugin doesn’t add rel=”nofollow” to the My Latest Tweets widget (see on the right in the sidebar).

Therefore I have just added the corresponding code to the plugin’s PHP file and thought I should share this information because it might really be useful for other people.

Adding rel=”nofollow” to the Twitter links

First make a backup of the file wp-content/plugins/twitter-for-wordpress/twitter.php and save it as twitter.org.php in the same directory. Afterwards open the file twitter.php and modify the code as highlighted here. You need to scroll to the right to see the highlighted code:

function hyperlinks($text) {
    // match protocol://address/path/file.extension?some=variable&another=asf%
    $text = preg_replace("/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/i"," <a rel=\"nofollow\" href=\"$1\" class=\"twitter-link\">$1</a>$2", $text);
    // match www.something.domain/path/file.extension?some=variable&another=asf%
    $text = preg_replace("/\s(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/i"," <a rel=\"nofollow\" href=\"http://$1\" class=\"twitter-link\">$1</a>$2", $text);
    // match name@address
    $text = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/i"," <a rel=\"nofollow\" href=\"mailto://$1\" class=\"twitter-link\">$1</a>$2", $text);
    return $text;
}
function twitter_users($text) {
       $text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a rel=\"nofollow\" href=\"http://twitter.com/$2\" class=\"twitter-user\">@$2</a>$3 ", $text);
       return $text;
}

After you have added the code save the file, upload it you your server and you’re done.

If you are using the WP Super Cache plugin be sure to empty the cache so that all pages are updated.

tweetthis-15

How To Achieve Maximum Website Performance (Part 1)

Saturday, May 9th, 2009

The idea for this article came to my mind when I was wondering why twitter.com is so slow sometimes. When looking at the source code of my profile homepage on Twitter I was really shocked because I still cannot understand why such a reputable company with so many users does not use all of the methods and processes available to increase the performance of their website.

But first things first. Before you’re going to analyze your website to find out what you can optimize to increase the performance of your website you need to install the following addons and Firefox of course.

I have also compiled a comprehensive list of Firefox addons for developers but you only need the addons listed above to follow the steps described in this article series.

1. Finding The (Maybe Not So Usual) Suspects

It is important that you empty your browser cache first.

Now just open the website in your Firefox you wish to speed up.

At the bottom of the browser in your status bar you will see information collected by the lori addon.

Screenshot of "Life Of Request" info

Screenshot of "Life Of Request" info

Time To First Byte

The first value shows you how long it took for the first byte to arrive. On this blog’s homepage it took just about 0.157 seconds. If you have dynamic data on your page and maybe even database queries on your site the value may actually be much higher.

This value is important to optimize your code on the server side. If you see something like more than 0.5 seconds or even a value greater than one second you know that you have to optimize your server-side code (more on that later).

Total Load Time

The second value shows how long it took until all of the elements on the page had been loaded - this includes embedded images and everything else - even external scripts and embedded video players. If this value is higher than about two to three seconds you know that you need to optimize the code on the client side.

Total Number Of Bytes

The third value shows the total number of bytes transferred which also includes images, scripts etc. Depending on your site and your target audience this value may be quite high but in most of the cases it should not exceed 200K (if your site is a blog it may be up to 500K in my opinion).

Number Of HTTP Requests

The fourth value shows you how many separate HTTP requests to a server were required. Your goal should be to minimize this number. At the time of writing there were 37 HTTP requests required on this page (and 5 requests on reload which is shown in the screenshot) which is quite a large value. Every HTTP request (especially if the request goes to different servers) results in a delay of your page being displayed.

There is no rule of thumb regarding this value - it depends on the nature and contents of your site but it should always be as low as possible.

2. Optimizing The Time To First Byte

If the time to first byte value is quite high you need to optimize your server-side code. As there is no general rule for all the different backends, applications and content management systems I can only give general recommendations here yet I will also show you how to decrease this value if you are using WordPress on your own server (not the hosted blogs at Wordpress.com).

Static Page

If the page you are trying to optimize is a completely static page (like a real HTML file) and the value is relatively high I would interpret this as your server being too slow or being under a high server load. You should check this with your webhost as a static page should be delivered by webservers in a very short amount of time.

Dynamic Page

If your page is a dynamic page developed in PHP, Perl, Ruby-On-Rails, JSP or any other web development language or system there may be much to optimize depending on the nature of your page.

Do you have many content on your website that is retrieved dynamically?

You may for example have the latest comments by users in your forum, on your blog or the latest images or postings on your page. If you are not caching these contents (or the page) on your server yet just ask yourself the following question:

What is the access-to-update ratio, i.e. how often is the specific page accessed by someone and how often do you change or update the contents?

If you have many people accessing your page yet you only update it hourly or even daily or weekly you should implement caching on your server. You may for example just update the contents on the page every X minutes from the database or you may use what I call intelligent caching where you only update cache files if the content has changed. This is actually what I am using on most of my own sites: when a new user joins the cache file containing the HTML code for the “new users” snippet is deleted. Whenever someone then accesses the page the PHP script on the server checks if the cache file is available and loads it in that case. If it is not available it is created just-in-time, cached and will be used as long as it exists.

Implementing a caching algorithm is however very dependent on the language your code is written in and depends on your framework or application so I cannot go into detail on that matter, regretfully, as there is not a one-fits-all solution.

WordPress

I am using WordPress on this blog as well (as you might already have guessed) so I can give you some advice on how to optimize your pages.

I have seen many plugins for WordPress that have not been developed with getting lots of traffic in mind. Some retrieve the data from an external source (like your Twitter feed) on every single page request which not only increases load time it also means that your blog may be unavailable if Twitter (or any other source a plugin may be using) is down. This also leads to a huge amount of traffic to the external sources. You should check if the plugins you are using are requesting dynamic content from external sources on every single reload of a page.

Remember: whenever you access such a blog page data is retrieved from the external source before the page is displayed to the user (because it is server based). If these pages would be cached on the server for a limited amount of time this problem would be solved (to the most part).

There is actually a great caching plugin available for WordPress. It is called WP Super Cache and can be downloaded or installed directly from within WordPress. It decreases the load time of your WordPress pages dramatically because with the default installation WordPress pulls all article data on every request from the database so the database is really your bottleneck if you are getting lots of traffic to your site. WP Super Cache not only caches the pages it is also very intelligent in that it regenerates cache files automatically if you update your posts.

More info on WP Super Cache is available on this page as well.

This concludes the first part of the series. Continue to read the second part of this series.

tweetthis-15

Free “Tweet This” Buttons For Your Homepage

Wednesday, May 6th, 2009

It’s a bit funny. When I wrote the articles regarding how to create “Tweet This” buttons with PHP and with JavaScript I was pretty sure that I had already created “Tweet This” buttons for your homepage but in fact I simply had forgotten it.

So I have just created some new buttons just for that purpose. You can download the full package below for free. As always I’d appreciate a link back to this page but this is not required.

Just follow the instructions in the articles linked above. A working JavaScript demo is included in the download.

These are the images that are contained in this package:

Tweet This Buttons

Tweet This Buttons

downloadnow-free

If you like the graphics included in the package I’d appreciate if you’d retweet it by clicking on the “Tweet This” button below. Download the full package with many more graphics here.

tweetthis-15

How To Create A Dynamic “Tweet This” Button With JavaScript

Wednesday, May 6th, 2009

Yesterday I posted some code on how to create dynamic Tweet This buttons with PHP, today I’m going to share a short code snippet you can really drag and drop into your editor to create a “Tweet This” button on your website.

You just need to copy and paste this code and adjust the src attribute of the image to point to your button:

<script type="text/javascript">
var twtTitle  = document.title;
var twtUrl    = location.href;
var maxLength = 140 - (twtUrl.length + 1);
if (twtTitle.length > maxLength) {
twtTitle = twtTitle.substr(0, (maxLength - 3))+'...';
}
var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + twtUrl);
document.write('<a href="'+twtLink+'" target="_blank"'+'><img src="tweetthis.gif"  border="0" alt="Tweet This!" /'+'><'+'/a>');
</script>

tweetthis-15

How To Create A Dynamic “Tweet This Button” With PHP

Tuesday, May 5th, 2009

Yesterday I have just released some of my graphics for Twitter that I have designed myself.

This time I will show you how can easily create links to your own pages on your website or different articles whenever you have both a page URL and a page title available.
This code automatically removes characters from the end of the title so that in addition to the URL itself and a space character between the maximum length of 140 characters will not be exceeded. If the title is too long it will be truncated and three dots will be appended to show that it has been shortened.

When clicking on the link the user is taken to the Twitter homepage with the message already preset so that he can tweet it immediately with just a single click.

function getTweetUrl($url, $title)
{
$maxTitleLength = 140 - (strlen($url)+1);
if (strlen($title) > $maxTitleLength) {
$title = substr($title, 0, ($maxTitleLength-3)).'...';
}
$output = "$title $url";
return 'http://twitter.com/home?status='.urlencode($output);
}
?>
Example usage:
<a href="<?php echo $url; ?>" target="_blank"><img src="tweetthis.gif" border="0" alt="Tweet This!" /></a>

tweetthis-15

Free Twitter Follow Me Buttons And Graphics

Monday, May 4th, 2009

I just thought I’d share some of the Twitter graphics I have created with you as a way of saying thank you for visiting my blog. Hope you like it by the way. If you do why not follow me on Twitter?

The complete package contains these and some more Twitter buttons you can add to your homepage or blog for free - I always appreciate a link back to this blog (or this specific page) however. If you like these graphics why not retweet by clicking on the “TWEET THIS ARTICLE” button below?

Here is a preview of the graphics contained in the package:

Free Twitter Graphics and Buttons

Free Twitter Graphics and Buttons

Simply click below to download the free graphics package:

downloadnow-free

Download the full package with many more graphics here.

tweetthis-15

Get More Followers - tweet.ms Bar Now Publicly Available

Tuesday, April 28th, 2009

I have just released the new tweet.ms bar. tweet.ms already allows you to create short URLs which redirect to the target page. Now you can also select to add a tweet.ms bar to your link as well which will result in the link page being displayed under the bar (if the result page has no frame breaker that is).

Now anyone who likes your shared link can directly follow you on Twitter by entering his user name and password in the bar. The user will then follow you immediately. Furthermore not only is the Twitter user name and the password never stored on the tweet.ms servers but the user can actually opt in to have an encrypted cookie stored on his PC that contains his Twitter user name and password so that he can use the tweet.ms service easily by being logged in yet never has to enter his credentials again. And his login data is stored only on the local PC - never on the server itself.

Of course the user can also retweet the message directly from within the bar or share the (original) link via various social bookmark services like del.icio.us, digg and so on.

Just see for yourself and try it out - I’m sure you’ll like it:

http://tweet.ms/6n

Comments and feedback are always appreciated - I like to hear from you.

tweetthis-15

tweet.ms URL Shortening Service Features New Graphical Statistics

Thursday, April 23rd, 2009

I just finished adding the new statistics feature to the tweet.ms URL shortening service.

Every link has a unique statistics URL that is shown after the short tweet.ms URL has been created and shows the number of visitors (both bots and humans are distinguished), the countries the visitors are coming from and a timeline showing the visits within the last days as a line chart.

Additionally pie charts are available for both browser names (Firefox, Internet Explorer and so on) and operating systems. A list of all the different referrers (100 maximum) is also included.

New cool features are coming soon. I have many new and exclusive features in store so stay tuned and most of all: use tweet.ms often in your tweets as your URL shortening service and support this free service.

See some statistics here

tweetthis-15