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:

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.

Continue reading

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/

Codeigniter set up on the nginx http server

Setting up nginx http server was not so bad I thought. Setting up Codeigniter on my server was easy (Just follow the instruction in their documentation).

However, codeigniter redirect was not working except the one that is set up in $route[‘default_controller’] = “blahblah”;…

If you encounter the same problem as I struggled from, find the config.php from /application/config/ directory and search for “$config[‘uri_protocol’] = “blahblah”;

When you look at its documentation carefully, it says :

If your links do not seem to work, try one of the other delicious flavors:

So I changed it to “REQUEST_URI” and my Codeigniter’s rewrite rule started working!

If you wonder what my conf file looks like, here it is: