JQuery.js Or JQuery.min.js

If you’re running JQuery on a production site, which library should you load? JQuery.js or JQuery.min.js? The short answer is, they are essentially the same, with the same functionality.

One version is long, while the other is the minified version. The minified is compressed to save space and page load time. White spaces have been removed in the minified version making them jibberish and impossible to read.

If you’re going to run the JQuery library on a production site, I recommend that you use the minified version, to decrease page load time, which Google now considers in their page ranking.

Another good option is to use Google’s online javascript library. This will save you the hassle of downloading the library, as well as uploading to your site. In addition, your site also does not use resources when JQuery is loaded.

The latest JQuery minified version from Google is available here.

You can link to it in your pages using:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Twitter Shutting Down Basic Authentication

On August 31, the Twitter API team will shutdown all basic authentication on the Twitter API. If you are using any of the third-party Twitter-based applications that uses basic authentication, the application you’re using will no longer work as of August 31.

Twitter has given developers enough warning of the switch. In fact, Twitter has postponed the cutoff date at least twice in the past few months to accommodate developers into adopting the OAuth authentication protocol. This time, the cutoff date will most likely stick. What this means is there will be a number of applications that will no longer work after the deadline.

How does this affect you? If you are a WordPress user and you are using a Twitter-based plugin that requires authentication, there is a good chance your plugin does not use OAuth authentication. There at least 250 Twitter plugins written for WordPress. A number of them do not require authentication, but some require authentication.

If your plugin requires authentication, better check.

One way of finding out which plugin uses OAuth is to check the plugin’s Option pages. If you’ve entered your Twitter credentials such as username and password, then you are using the older and soon to be obsolete basic authentication.

If you’ve entered a consumer key and a consumer secret key, then you are using OAuth authentication protocol.

Another way of finding out if your plugin uses OAuth is that the login process should take you back to the Twitter’s login page such as the example below.

To be sure, check for updates of your plugin. If the developer does not plan to update the plugin, better start looking for an alternative.

I didn’t get a chance to look at each plugin because of the sheer number of Twitter-based plugins in the Plugins directory. One plugin that supports OAuth is Twitter Tools.

Add Twitter Trends To Your WordPress Blog

Several months ago, I wrote a post on how to retrieve Twitter trends. Today, I’ll show you how to add and display Twitter Trends in your WordPress theme. First, the code to retrieve Twitter trends.

function get_twitter_trends() {
  $contents = @file_get_contents("http://search.twitter.com/trends.json");
  if (strpos($http_response_header[0], "200")) {
    $json = json_decode($contents);
    foreach ($json->trends as $trend) {
      echo $trend->name;
    }
  }
}

Add this function in your theme’s functions.php file. If you want to make the trends clickable, then use the Twitter search link. This will send users to the Twitter Search page when they click on a trend.

echo '<a href="http://twitter.com/#search?q='.$trend->name.'">'.$trend->name.'</a>';

Finally, place this code in your WordPress theme where you deem appropriate.

if ( function_exists( 'get_twitter_trends' ) ) get_twitter_trends();

Google Font API

I had a little fun this morning playing around with Google Font API. With just a couple of quick codes on your webpage, blog or website, you can really style your sites using over a dozen beautiful fonts available from the Google Font Directory. The usage is pretty straightforward. See sample below. Just add a stylesheet reference in your header. Add some CSS elements in your stylesheets. Tada. Your done. Your website is now using Google’s web fonts. The advantage is you get a choice of high quality open source fonts, it works in most browsers, and it’s extremely easy to use.

Header

<link rel=”stylesheet” type=”text/css” href=”http://fonts.googleapis.com/css?family=Tangerine”>

Stylesheet

body { font-family: ‘Tangerine’, serif; }

If you want a little bit more control, flexibility and speed, you can use Font Loader. It’s a little bit more involved. It requires the use of Javascipt. You can also take advantage of TypeKit.

Retrieve The Latest Twitter Trends

Here’s a simple and short tutorial on how to retrieve Twitter trends. We will be using PHP and Twitter’s API to retrieve the latest trends. You can publish the trends on your website, blog or any application you are working on. So, let’s get started.

Twitter has made trends available to anyone via API calls. The url of the API is: http://search.twitter.com/trends.json. Trends is also available in XML, but we will use JSON in this example.

To retrieve the string of data, we will use a PHP command called file_get_contents. We will suppress errors by placing an @ sign in front of file_get_contents. We will assign the string to a variable called $contents. So this is what we have so far.

$contents = @file_get_contents("http://search.twitter.com/trends.json");

Next, we will check if we have the correct response from the http_header. We will check for the code “200”, meaning we have a valid response. We will use the PHP command called strpos to find the needle in the haystack. The needle in this case is “200.” We will look for it starting at position “0.” The format is going to be like this.

$contents = @file_get_contents("http://search.twitter.com/trends.json");
if (strpos($http_response_header[0], "200")) {
  echo "ok";
} else {
  echo "fail"
}

Ok, so we now have a JSON string assigned to the variable named $contents. We just need to decode it using the PHP command called “json_decode” and assign it to the $json array variable. Next, we will run a foreach contruct to echo each trend name.

$contents = @file_get_contents("http://search.twitter.com/trends.json");
if (strpos($http_response_header[0], "200")) {
  $json = json_decode($contents);
  foreach ($json->trends as $trend) {
        echo $trend->name;
      }
} else {
}

So, there you have it. We now have the latest Twitter trends using PHP and Twitter’s API.

Add APIs to your projects

If you have a web service, you can add functionality to it by allowing other programs to access to your service through the use of APIs or Application Programming Interface. The following article talks about  two popular types of APIs using SOAP and REST. It explains in detail the basics of API programming.  It’s a good article to get you started in writing your own APIs. Read the rest of the article.