Skip to content


JavaScript String.replace with regex

I often use String.replace in JavaScript whenever I have to use JavaScript. Today was the day that I ended up with using it for my work. I know that String.replace supports regular expression to match your string, but I was not clear if I could use “capturing groups” and “quantifiers”. As I guessed, I was able to use quantifiers in the replace string like the sample below:

    var link_template = '<ol>\
        <li><label>Link 1 Title:</label><input class="text" id="relLink1title" name="relLink{1}title" value="" /></li>\
        <li><label>Link 1 URL:</label><input class="text" id="relLink1url" name="relLink{1}url" value="" /></li>\
        <li><label>Link 1 Img URL:</label><input class="text" id="rellink1imgurl" name="rellink{1}imgurl" value="" /></li>\
        <li class="btn"><span><a href="#" class="new-related-link">Add a New Link</a> | <a href="#" class="remove-related-link">Remove</a></span></li>\
        </ol>';
 
    link_template = link_template.replace(/(<label>.*?)(\d)(.*?<\/label>)/im, '$1 2 $2');

Posted in Frontend Tech, Programming, Tips. Tagged with , , , .

ByteArray in Flash slide

I found this ByteArray slides by Lee Brimelow, which he presented at the Flash on the beach.

I knew that low level manipulation is so powerful tool, but had very little idea of how I could use them. This slide shows a good start for a beginner like myself.

Peronally, I used bitwise operators to extract red, green, blue color values. However, with the bitwise operators it works for many other things.

One of samples that Lee Brimelow presented was this:

for (var i=0;i<100;i++) {
    if (i&1) {
        // i is odd
    } else {
        // i is even
    }
}

To check whether the number is odd or even and according to Lee, it’s 600% faster than using the modulus operator.

Posted in News, Programming. Tagged with , , .

Building Applications for the iPhone with Flash

Next Gen of Flash Authoring tool would allow developers to create native iPhone application.
Read more at the original source

This is a very great news!

Posted in News. Tagged with , , .

Initial Page Load – FE Performance Tuning

1. Introduction

Why is the site performance so important? The poor site performance impacts company’s revenue and user’s engagement.

  • Shopzila: 5 seconds speed up resulted in a 25% increase in page views, 10% increase in revenue, a 50% reduction in hardware, and a 120% increase traffic from Google.
  • Amazon: every 100ms of latency cost them 1% in sales
  • google: extra .5 seconds in search page generation time dropped traffic by 20%
  • a broker could lose $4 million in revenues per millisecond if their electronic trading platform is 5 milliseconds behind the competition.
  • facebook: regardless of site speed, users spend around the same amount of time on facebook, which means if the site is running slowly users are going to be seeing fewer pages in the same amount of time.

So the conclusion is that fast site is better.

2. Site performance is Latency experienced by users

It’s measured from a guest request to the presentation of the page at the browser. There are many factors that contribute to the site performance. Facebook has defined 3 factors and those are:

  • network transfer time – time from the user’s browser to the server.
  • server generation time – time spent on the server
  • client render time – time the browser spends on parsing the HTML, loading JavaScript/css/images and rendering contents.

80-90% of the end-user response time is spent on the frontend according to Todd hoff. Therefore, it is a logical decision that it is better to focus on the frontend before jumping into other areas for the site performance.

(Site benchmark is also important, When the site cannot serve as many guests as it should, FE optimization won’t matter.)

3. Page Speed & YSlow Tips

We have heard about them so many times already and are well aware of those tips. However, few tips from Page speed are worthy to look at.

3.1 Optimize the order of styles and scripts

Many browsers block the downloading of resources referenced in the document after scripts until those scripts are downloaded and executed. On the other hand, if other files are already in the process of being downloaded when a JS file is referenced, the JS file is downloaded in parallel with them

The recommendations from google Page Speed are :

  1. Put external scripts after external stylesheets if possible
  2. Put inline scripts after other resources if possible.

For more details, go to the source link specified in the section.

Source: http://code.google.com/speed/page-speed/docs/rtt.html#PutStylesBeforeScripts

3.2 Defer Loading of JavaScript

Deferring loading of JavaScript functions that are not called at startup reduces the initial download size, allowing other resources to be downloaded in parallel, and speeding up execution and rendering time.

Source: http://code.google.com/speed/page-speed/docs/payload.html#DeferLoadingJS

Defer loading of JavaScript has been one of my focuses for the site performance in fact.

4. Focus on the viewable area

[diagram here]

It’s recommended to focus on the portion of the page that guests see first as they come to the site. This concept is very similar to the news feed on the facebook home page. 15 stories are loaded at first as the initial load. After that, additional 15 stories appear as user scrolls down.

What Yang found, however, is that when people do scroll beyond the initial 15 stories they’re shown, they’re happy to wait the extra second or two for 30 new stories to load, which results in a significant boost in engagement.

5. Deferload everything if possible

According to the research done by clicktale blog :

  • between 64% to 68% of the page views are likely to reach the 1k pixel line and 15% to 20% will reach the bottom of the page.
  • Below 540 pixels, both visitor attention and page exposure decline exponentially.
  • The most valuable web page real-estate is located near the page top, between 0 and 800 pixels. Visitor attention and page exposure peak at about the 540 pixel-line.

That could translate into this: the page components below the viewport are not likely to be downloaded for 32% to 36% of users if the defer loading technique were implemented. If the entire page’s file size were 200KB and then file size of the page components (mainly images and flash media file) out of viewport were 50KB, our target size for the initial load would be 150KB (potentially 33% less download for users). Although there might be guests that scroll down to all the way bottom, there are guests that click away from the first screen.

Source: http://blog.clicktale.com/2007/10/05/clicktale-scrolling-research-report-v20-part-1-visibility-and-scroll-reach/ & http://blog.clicktale.com/2007/12/04/clicktale-scrolling-research-report-v20-part-2-visitor-attention-and-web-page-exposure/

References

- More To Come -

Posted in Frontend Tech, Tips. Tagged with , , .

JavaScript Debugging in Internet Explorer

This is to bookmark to an article on how to debug JS in Internet Explorer.

Check out how

Posted in Frontend Tech, Tips.

Inspired startup

This is a blog site by Andy, a serial entrepreneur and angel investor. I found entries by him very inspirational. I often read his posts. Here’s the link.

Posted in Personal. Tagged with , , .

RESTful web services

Many developers heard/use/implement/develop RESTful web services daily basis including myself. It seems likely that we all know what it is and how it works. However, if we ask ourselves why we are using it, what would be your answer?

My answer to this question is this:

To make *services* more sense.

We all know that RESTful web services utilizes http methods such as GET, POST, PUT, and DELETE. Most commonly used methods to me are GET and POST. And technical aspects of discussion can keep going. However, the question is how we can utilize RESTful web services and how we can make it so that other developers can consume them in easy way? Eventually RESTful web services is for openness. Facebook opens up their RESTful API so that other developers or 3rd party application of facebook can pull up information on users or something like that.

With RESTful API, it is *possible* that you can organize calls.

Let’s look at this imaginable API path for getting a particular movie info.

http://RESTfulAPIHost:Port/movie/

By just looking at the API path, you can take a good guess of what it might return to you. And then after that, you naturally think ahead and append movies name to it.

http://RESTfulAPIHost:Port/movie/dark-knight/

Looking at the API path, I would naturally think that I could expect movie information for the movie “Dark Knight”. This natural thought process leads to more details API paths like these:

http://RESTfulAPIHost:Port/movie/dark-knight/actors/

http://RESTfulAPIHost:Port/movie/dark-knight/credits/

http://RESTfulAPIHost:Port/movie/dark-knight/showtimes/

Posted in Programming, Tips. Tagged with , , , .

Need to write down more often.

I just realized that writing down knowledge or techniques that I’ve already known or practices for a long time helps me organize them in the brain well. Some people talk about a particular topic and I just hear over what they talk thinking “I know about it and have used it already” and then do not join the conversation. That’s a big mistake that I make every single day.

It’s like this: Let’s imagine for seconds. There are many post-its on a table with specific instructions on them for tasks. When there are 10 of them, you can easily find them. However, when there are over 100 or 1000 of them, finding the right post-it note is merely impossible or it will take at least several minutes to several hours. Over time, those post-its will get stacked more and more.

Organizing post-its will definitely get you to find the right one much faster. I think brain works that way. You gain so much knowledge daily basis and if you don’t organize your knowledge well it will be like you have 1000 or move post-its notes everywhere on your desk. I think writing down those things helps you organize your knowledge. Also it can be your future references when you need to recall how you did it in the past.

Posted in Personal.

Samsung LN46B650 Review

I recently ordered Samsung 46 inch LCD TV, which of model number is LN46B650. Actually it has not arrived yet. So I can’t really give a review yet. However, when I receive the TV (which is supposed to be delivered this Sunday), I will definitely update this post as I play with it.

Here’s the photo of the TV set (links to amazon product page):

Researching Viewing Distance
My place is not big and distance from tv set to my couch is about just less than 6 feet, which is a little over the ideal view distance for 46″ LCD. However, I assumed that eventually I would move to a bigger place in next 1 or 2 years and decided to buy 46″ sized LCD TV. (I referred to cnet’s “Ultimate HDTV buying guide” article)

Checked!

Researching brands
This was the issue that took the most intensive research on my part. I’m a type of person who longs for a good quality product and believes that a good product does not come with cheap price. When it comes to brands, price usually includes the “brand” name plus the unique technologies used to make a particular product. And the technologies distinguish between good LCD TV and bad LCD TV. Therefore, at first two brand names came up: Sony and Samsung.

Sony is known for good quality of visuals and audios at consumer level as well as production level. That’s why Sony came as a first option obviously. 2nd runner was Samsung, whose LCD panels have been used for apple products such as iPhone and Cinema Display. If Apple uses Samsung, it must be good quality.

So basically I debated between two brands Sony and Samsung for a long time.

Decision, Order, and Delivery
I ordered it from bestbuy after comparing between sony (KDL-46V5100) and samsung (LN46B650). The main comparisons that I made are:

  1. color: Samsung model had better colors that were more saturated. So when I looked at two TV sets, red was more red on Samsung TV.
  2. black/white: The contrast on Samsung model was better looking than Sony one again.

As you can see, I did not consider the sound features in both tv sets because I would hook up my Bose speaker systems to a TV. What I cared the most was color and contrast. And from what I saw it from bestbuy display Samsung (LN46B650) beats Sony TV (KDL-46V5100) set.

The delivery happened in the morning. Delivery time frame was 9am to 12pm and they did within the frame. Bestbuy delivery guys set up the LN46B650 TV set on my living room and hooked up a DVD player, Bose speaker system, and HD Cable box. Everything worked without any issues. They also took my old CRT TV with them.

So whole purchase experience was very smooth from ordering to delivering.

Fun with Yahoo! Widget
I was skeptical about Yahoo! Widget first without using them. However, I found it very useful once youtube widget is installed on the tv. To be continued….

Posted in News, Personal.

geolocation in Firefox 3.5

I came crossed geolocation feature that was introduced in Firefox 3.5. That is very neat functionality that marketings will love for targeted ads. And also for web developer/engineers, it’s something that we can customize the web content based on the users’ location.

It used to require somewhat complex process to get (not technology side tho) the information.

Anyways, in this link you get to see how to access the core API for.

And then here’s the properties of position object:

  • QueryInterface
  • coords : xpconnect wrapped
  • timestamp
  • getInterfaces
  • getHelperForLanguage
  • contractID
  • classDescription : wifi geo location position object
  • classID
  • implementationLanguage
  • flags : 8
  • SINGLETON : 1
  • THREADSAFE : 2
  • MAIN_THREAD_ONLY : 4
  • DOM_OBJECT : 8
  • PLUGIN_OBJECT : 16
  • EAGER_CLASSINFO : 32
  • CONTENT_NODE : 64
  • RESERVED

And interestingly position.coords has some unique properties:

  • QueryInterface
  • latitude
  • longitude
  • altitude
  • accuracy
  • altitudeAccuracy
  • heading
  • speed

As you can see it has speed property. So in theory, with the available properties you can make GPS system on the web.

Posted in Frontend Tech, News.