Pacific Side

Pacific Side

Global Affairs, History, Philosophy, Literature, and the Glocalization of the Internet

28 May 2007

Yahoo and Google Survey

A survey of doctype and encoding usage across a couple of Yahoo and Google's international locales:

Yahoo!
- Doctype? Yes. HTML 4.01 Strict.
- Encoding specified? Yes. UTF-8.

Yahoo! Taiwan
- Doctype? Yes. HTML 4.01 Strict (but mixes in some XHTML syntax).
- Encoding specified? Yes. BIG5 (legacy traditional Chinese encoding).

Yahoo! Japan
- Doctype? No.
- Encoding specified? Yes. EUC-JP (legacy Japanese encoding).

Yahoo! China
- Doctype? Yes. XHTML 1.0 Transitional.
- Encoding specified? Yes. GB2312 (legacy simplified Chinese encoding).

Google
- Doctype? No.
- Encoding specified? Yes. UTF-8.

Google Taiwan
- Doctype? No.
- Encoding specified? Yes. UTF-8.

Google Japan
- Doctype? Yes. HTML 4.01 Strict (but mixes in some XHTML syntax).
- Encoding specified? Yes. UTF-8.

Google China
- Doctype? No.
- Encoding specified? Yes. UTF-8.

25 May 2007

Unicode UTF-8 Byte Order Mark

So, I setup this site with the intent of focusing on internationalization and localization as they relate to the web but have not done a whole lot of that yet. I have found that this is something I actually know more about just because I have developed in a multilingual (English, Chinese, Japanese) environment for a while. To kick this off, I thought I would put up a short blurb about the Unicode UTF-8 Byte Order Mark, otherwise known as the BOM. If you have ever seen  prefixing the first line of a file, then you have already been introduced. My thought here is not to discuss the nature of the BOM (you can check out the links below) but to mention some potentially lesser known facts about its use that developers may run into.

  • When saving a file in Notepad, if you save with "Encoding" set to "UTF-8" then you are including the BOM at the beginning of the file even though you cannot see it. Similarly, in Visual Web Developer, if you save the file with encoding and choose "Unicode (UTF-8 with signature) – Codepage 65001" then you are also including the BOM at the beginning of the file.
  • Properly using multilingual text on the web requires using files saved with Unicode encoding. There are usually a number of options. Generally, best practice is to not include the UTF-8 BOM, and I recommend choosing a Unicode encoding that both excludes the BOM and maintains a small file size. For example, in Visual Web Developer, I save files with the "Unicode (UTF-8 without signature) – Codepage 65001" encoding.
  • Having said that, I ran into the same case twice on my former blogging platform where I was forced to include the BOM at the beginning of an ASP file in order for it to properly recognize the script as Unicode and correctly process Unicode text. If all else seems to be failing, give it a shot and see if it fixes it. Still, my recommendation is to exclude the BOM unless it proves absolutely necessary.

Check out these links for more information:

20 May 2007

Object-Oriented JavaScript and setTimeout

Here are two examples of how to use setTimeout in an object constructor with public methods added to the prototype. Functions called using setTimeout are executed in the scope of the window object, so the this keyword does not apply. In both of these examples, clicking on a link triggers an alert after a pause of two seconds. In the first example, the alert function and the setTimeout are both in a public method of the object instance. In the second example, the setTimeout is in one public method while the alert is in another.

Example 1

var myObject = function(myArgument) {
    this.myProperty = myArgument;
    this.myTrigger = document.getElementById('myLink');
    this.init();
};
myObject.prototype.init = function() {
    this.myProperty = 'New Value';
    YAHOO.util.Event.addListener(this.myTrigger, 'click', this.myMethod, this);
};
myObject.prototype.myMethod = function(e, obj) {
    var myFunction = function() {
        alert(obj.myProperty);
    };
    YAHOO.util.Event.preventDefault(e);
    setTimeout(myFunction, 2000);
};
new myObject('Initial Value');

Example 2

var myObject = function(myArgument) {
    this.myProperty = myArgument;
    this.myTrigger = document.getElementById('myLink');
    this.init();
};
myObject.prototype.init = function() {
    this.myProperty = 'New Value';
    YAHOO.util.Event.addListener(this.myTrigger, 'click', this.myMethod1, this);
};
myObject.prototype.myMethod1 = function(e, obj) {
    YAHOO.util.Event.preventDefault(e);
    setTimeout(function() { obj.myMethod2(); }, 2000);
};
myObject.prototype.myMethod2 = function() {
    alert(this.myProperty);
};
new myObject('Initial Value');

4 May 2007

Literal Notation and Object Constructors in JavaScript

Putting something up here again for my own reference. The comments on this article are the part that interested me. I like using object literal notation and wanted to know if it would be possible to write a reusable object constructor in literal notation. From all the discussion, it seems that making object constructors is best still done using a prototype function. Object literal notation is great for creating a single instance of an object but not ideal for creating an object constructor that can be used to create multiple instances of an object. If anyone knows differently, I'd be interested.

JSON for the Masses

Edit: Here are two sites that offer utilities to create constructor classes from an object in literal notation:

2 May 2007

YUI Library Review

Throwing this up here partly for my own reference.

AJAX: Selecting the Framework that Fits

Reviews five JavaScript libraries (Dojo, Prototype/Scriptaculous, Direct Web Remoting, Google Web Toolkit, and the Yahoo! User Interface Library) and evaluates them on a couple categories. Article picks the YUI library. Glad I use and am a part of that one. It's one of Yahoo's strongest points in my opinion. Check it out if you are looking for a JavaScript library:

http://developer.yahoo.com/yui/

Language

Trevor Powell © 2010. All rights reserved.